What's the cleanest way of editing the characters in a string in C#?
What's the C# equivalent of this in C++:
std::string myString = "boom";
myString[0] = "d";
When protyping we often do empty anchors. A very common way to do this is to do something like:
<a href="#">Go here</a>
But if the client clicks this link, the page will scroll to the top. But if we leave out the href attribute, the link won't behave like a link.
I've see stuff like:
<a href="javascript;">Go here</a>
But it doesn't look right.
Any other ideas?
Hi!
I try to upload file, how can i check if file is upload
when i send empty input witch file upload i get
AttributeError: 'unicode' object has no attribute 'filename'
How can i check added file?
hey
i have the following domain model:
class Location {
String name
static hasMany = [locations:Location, persons:Person]
}
class Person {
String name
}
so basically each location can hold a bunch of people + "sub-locations".
what is the best way to recursively query for all persons under a location (including it's sub locations, and their sub locations, etc')?
in java is the name of a method a string? why or why not?
so if i have something like:
public static int METHODNAME (some parameters or not)
{
something to do ;
}
is METHODNAME a string?
Is there an easy way to get a summary string of the errors that have been added to a controller's modelstate?
I'm looking to return this in an Ajax method and want the validation errors etc to be returned to the client (i.e. the view does not exist for this method call).
Or do I have to loop through the modelstate and look at each object and extract the error text manually?
Howdy,
I'm setting up a Filament Group jQuery UI slider and using it in a gradebook.
We need to allow teachers to set a desired background range (to show the desirable values vs. the actual value for a given grade). I'm hoping to set a shaded area (as shown in this picture) that would indicate to people viewing the slider which values are desirable. If the handle is within the desired ranges, then the value is satisfactory. If the handle is out of the background shaded range, then some changes may need to happen.
Any suggestions on how to accomplish this? Based on what I've experimented with using Firebug, it looks like a <div class="ui-slider"> is setup, but the values inside of it don't seem to allow setting background-colors (only the div allows for that).
Thanks for your help.
I feel a little stupid for having to ask this… But I can't seem find it documented anywhere.
If I've got a Model with FileField, how can I stuff an uploaded FILE into that FileField?
For example, I'd like to do something like this:
class MyModel(Model):
file = FileField(...)
def handle_post(request, ...):
mymodel = MyModel.objects.get(...)
if request.FILES.get("newfile"):
mymodel.file = request.FILES["newfile"]
But that doesn't appear to work.
I am new to .Net platform. I did a search and found that there are several ways to do parallel computing in .Net:
Parallel task in Task Parallel Library, which is .Net 3.5.
PLINQ, .Net 4.0
Asynchounous Programming, .Net 2.0, (async is mainly used to do I/O heavy tasks, F# has a concise syntax supporting this). I list this because in Mono, there seem to be no TPL or PLINQ. Thus if I need to write cross platform parallel programs, I can use async.
.Net threads. No version limitation.
Could you give some short comments on these or add more methods in this list? Thanks.
I asked a question some time ago about creating a random circular partner assignment using php and mysql. This is a related issue.
I am working from the following code to try to give two users new, randomly selected partners:
$q = "SELECT user_id FROM users WHERE partner='$quit_partner' AND status='1'";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
while ($row = mysqli_fetch_array($r)) {
$users[] = $row[0];
}
$current = end($users);
$partners = array();
foreach ($users as $user)
{
$partners[$user] = $current;
$current = $user;
$q = "UPDATE users SET partner='{$partners[$user]}' WHERE user_id='{$user}'";
mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
}
Basically, a particular user (lets say user #4) quits the activity, leaving multiple other users without a partner (hypothetically, users # 5,6,7). I need to find out who those users are, hence the first query. Once I find them, I throw them into an array.
Then comes the difficult part. I want those newly partnerless users (5,6,7) to be randomly assigned new partners from everyone in the table.
The current code is flawed in that it only assigns the newly partnerless users eachother.
Thanks for your help.
So yesterday we had a table that has an auto_increment PK for a smallint that reached its maximum. We had to alter the table on an emergency basis, which is definitely not how we like to roll.
Is there an easy way to report on how close each auto_increment field that we use is to its maximum? The best way I can think of is to do a SHOW CREATE TABLE statement, parse out the size of the auto-incremented column, then compare that to the AUTO_INCREMENT value for the table.
On the other hand, given that the schema doesn't change very often, should I store information about the columns' maximum values and get the current AUTO_INCREMENT with SHOW TABLE STATUS?
I'm parsing Xml data which has entries like this:
<item name="UserText" type_name="gh_string" type_code="10"> </item>
I'm supposed to read the 6 spaces as a String, but both the InnerText and InnerXml values of the System.Xml.XmlNode are zero length Strings.
Is there any way I can get at this whitespace data in existing files and what do I need to do in the future to prevent this sort of screw up?
Is it possible to have VIM auto populate a file based on the extension?
For example, when I open a new .sh file, I would like VIM to automatically type
#!/bin/bash
as the first line. (This example simplified down to the essentials)
Today I set up the input in my application for all the different keys. This works fine except for virtual keys, for example, caret or ampersand. Keys that normally need shift to be got at. Using SDL these virtual keys don't work. As in they do not register an event.
if (event.type == SDL_KEYDOWN) {
switch (event.key.keysym.sym) {
case SDLK_CARET:
Keys[KeyCodes::Caret] = KeyState::Down;
break;
case SDLK_UP:
Keys[KeyCodes::Up] = KeyState::Down;
break;
default:
break;
}
I am absolutely sure my system works with physical keys like Up. The program queries a keystate like so:
if (Keys[KeyCode] == KeyState::Down) {
lua_pushboolean(L, true);
} else {
lua_pushboolean(L, false);
}
KeyCode is passed in as an argument.
So why are virtual keys, or keys that need shift to get at not working using SDL's KeyDown event type? Is more code needed to get to them? Or am I being stupid?
This line:
used_emails = [row.email for row
in db.execute(select([halo4.c.email], halo4.c.email!=''))]
Returns:
['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']
I use this to find a match:
if recipient in used_emails:
If it finds a match I need to pull another field (halo4.c.code) from the database in the same row. Any suggestions on how to do this?
I am working on a program where each item can hold an array of items (i'm making a menu, which has a tree-like structure)
currently i have the items as a list, instead of an array, but I don't feel like I'm using it to its full potential to simplify code. I chose a list over a standard array because the interface (.add, .remove, etc...) makes a lot of sense.
I have code to search through the structure and return the path of the name (i.e. Item.subitem.subsubitem.subsubsubitem). Below is my code:
public class Item
{
//public Item[] subitem; <-- Array of Items
public List<Item> subitem; // <-- List of Items
public Color itemColor = Color.FromArgb(50,50,200);
public Rectangle itemSize = new Rectangle(0,0,64,64);
public Bitmap itemBitmap = null;
public string itemName;
public string LocateItem(string searchName)
{
string tItemName = null;
//if the item name matches the search parameter, send it up)
if (itemName == searchName)
{
return itemName;
}
if (subitem != null)
{
//spiral down a level
foreach (Item tSearchItem in subitem)
{
tItemName = tSearchItem.LocateItem(searchName);
if (tItemName != null)
break; //exit for if item was found
}
}
//do name logic (use index numbers)
//if LocateItem of the subitems returned nothing and the current item is not a match, return null (not found)
if (tItemName == null && itemName != searchName)
{
return null;
}
//if it's not the item being searched for and the search item was found, change the string and return it up
if (tItemName != null && itemName != searchName)
{
tItemName.Insert(0, itemName + "."); //insert the parent name on the left --> TopItem.SubItem.SubSubItem.SubSubSubItem
return tItemName;
}
//default not found
return null;
}
}
My question is if there is an easier way to do this with lists? I've been going back and forth in my head as to whether I should use lists or just an array. The only reason I have a list is so that I don't have to make code to resize the array each time I add or remove an item.
So, I'm working with a really old system which uses a person's mysql database credentials to authenticate to a web site (the database was originally only accessed from the command line, but is now accessed from a php frontend). Because of some internal reasons (and to preserve the user's history), I have to leave the old authentication intact. I've been charged with adding openid authentication to this system. Somehow I need to be able to retrieve a users mysql username and password upon logging into the site through openid (using the Zend framework, by the way). I've thought of simply requiring registration at the first login, where the user must provide their mysql credentials, but I'd rather not store the password plain text.
I've also considered blanking everyone's mysql passwords, and just setting the user's mysql username manually (rather than having the user provide this, since they could provide any username).
This is turning into a security nightmare. Does anyone have any suggestions for alternatives?
This is running on a Linux server, by the way. Also, I can't use mysql pluggable authentication because the mysql version is 5.0 (pluggable authentication requires mysql 5.5), and no, I can't update it.
I have a need to design a system to track users memberships to groups with varying roles (currently three).
class Group < ActiveRecord::Base
has_many :memberships
has_many :users, :through => :memberships
end
class Role < ActiveRecord::Base
has_many :memberships
has_many :users, :through => :memberships
end
class Membership < ActiveRecord::Base
belongs_to :user
belongs_to :role
belongs_to :group
end
class User < ActiveRecord::Base
has_many :memberships
has_many :groups, :through => :memberships
end
Ideally what I want is to simply set
@group.users << @user
and have the membership have the correct role. I can use :conditions to select data that has been manually inserted as such :
:conditions => ["memberships.grouprole_id= ? ", Grouprole.find_by_name('user')]
But when creating the membership to the group the grouprole_id is not being set.
Is there a way to do this as at present I have a somewhat repetitive piece of code for each user role in my Group model.
I'm trying to edit a legacy wss3 sharepoint site.
Messing around with a 700+ code lines aspx page I got a "The server tag is not well formed." error on sharepoint and The ?content=1 trick does not work.
Anyone has a tip on how to get to the line that's causing the problem?
I'm expecting something like the aspnet ysod, at least that's usefull.
If it's worth something, I have access to the actual server.
Is there a simple framework for processing form submissions via a servlet? For my needs, a framework like STRUTS seems like over kill.
My ideal processor would be a servlet that converts form elements into a bean object, possibly using typing information in the form to help with the conversion. Does something like this exist or is there another solution out there geared toward simpler needs?
Thanks!
I have very little programming knowledge; only a fair bit in Visual Basic.
How do I take a value from a text field, then do some simple math such as divide the value by two, then display it back to the user in the same field?
In Visual Basic you could just do txtBoxOne.text = txtBoxOne.text / 2
I understand this question is more than one question and is very basic stuff, but I need to get my head out of Visual Basic and into where I should be :)
I am using MS AJAX ASP.NET Components (Calendar Extender) and I'm finding this problem.
Some weekdays are not being displayed....
I uploaded a picture so you can view exactly how it is being displayed...
The one on the right (calnder) in the picture is taken from microsoft's sample.
Have you got any idea what is causing this problem?
See screenshot: http://www.sajtkik.com/calendar.jpg
Thanks Alot!
There's always a need to make method names as concise as possible but without getting too long and waffly.
At what point is a method name far too long to possibly be justified?
I am wandering the desert of my brain.
I'm trying to write something like the following:
class MyClass {
// Peripherally Related Stuff
public:
void TakeAnAction(int oneThing, int anotherThing) {
switch(oneThing){
case THING_A:
TakeThisActionWith(anotherThing);
break;
//cases THINGS_NOT_A:
};
};
private:
void TakeThisActionWith(int thing) {
string outcome = new string;
outcome = LookUpOutcome(thing);
// Do some stuff based on outcome
return;
}
string LookUpOutcome(int key) {
string oc = new string;
oc = MyPrivateMap[key];
return oc;
}
map<int, string> MyPrivateMap;
Then in the .cc file where I am actually using these things, while compiling the TakeAnAction section, it [CC, the solaris compiler] throws an an error: 'The function LookUpOutcome must have a prototype' and bombs out.
In my header file, I have declared 'string LookUpOutcome(int key);' in the private section of the class.
I have tried all sorts of variations. I tried to use 'this' for a little while, and it gave me 'Can only use this in non-static member function.' Sadly, I haven't declared anything static and these are all, putatively, member functions. I tried it [on TakeAnAction and LookUp] when I got the error, but I got something like, 'Can't access MyPrivateMap from LookUp'.
MyPrivateMap could be made public and I could refer to it directly, I guess, but my sensibility says that is not the right way to go about this [that means that namespace scoped helper functions are out, I think]. I also guess I could just inline the lookup and subsequent other stuff, but my line-o-meter goes on tilt. I'm trying desperately not to kludge it.