After validation, i got error and return back to :action = :new.
Some field on form already filled, so i want to keep them filled afterr error message too.
How it can be done?
Thanks.
How would I execute a query equivalent to "select top 10" in couch db?
For example I have a "schema" like so:
title body modified
and I want to select the last 10 modified documents.
As an added bonus if anyone can come up with a way to do the same only per category. So for:
title category body modified
return a list of latest 10 documents in each category.
I am just wandering if such a query is possible in couchdb.
Looking for a way to retrieve a file size from a web server using cocoa/foundation. I know one can use NSURLconnection which will return NSURLResponse that contains the file size. Is there any other way to get the size. I'm looking for a synchronous way of doing it so when i do [myClass getsize] the size is returned.
Thanks
I need to design a function to return -ve numbers unchanged but should add a + sign at the start of the number if its alreay no present.
Example:
Input Output
----------------
+1 +1
1 +1
-1 -1
It will get only numeric input.
function formatNum($num)
{
# something here..perhaps a regex?
}
This function is going to be called several times in echo/print so the quicker the better.
Hi,
I wanted to store 10 in 4th position of array of 5 positions. How to do ?
int main( )
{
int a[5] = {,,,,4} ;
return 0;
}
If i do that i get error. Please help.
Thanks in advance.
Hi friends i am trying to move curser move to the next line. it is worked but when i enter a character in textview curser again back to first line. please help me any one. i am writing below code.` if (textView == mailBodyTxtVew)
{
textView.text= [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//[textView resignFirstResponder];
// return NO;
}
`
I'm trying to use flexjson to convert the following json string into a java object:
{"inboundDataNotification": {
"callbackData": "12345",
"inboundData": {
"message": "Hello World",
"messageId": "mes1234"
}
}}
Using the following method:
import flexjson.JSONDeserializer;
@RooJavaBean @RooToString @RooJson(fromJsonArrayMethod="", toJsonArrayMethod="", toJsonMethod="") public class InboundData {
private String messageId;
private String message;
public static InboundSMSMessage fromJsonToInboundSMSMessage(String json) {
return new JSONDeserializer<InboundSMSMessage>().use(null, InboundSMSMessage.class).deserialize(json);
} }
All fields are null after this method is invoked. Any ideas what to change here?
I am using basic modal dialog:
http://www.ericmmartin.com/projects/simplemodal-demos/
$(document).ready(function() {
$("#bodyTxt .basic").click(function() {
var text = $(this).attr("title");
$("#basicModalContent").html(text).modal();
return false;
});
});
but when i click on X code is now visible in page. How can after i close model dialog delete html code and add #basicModalContent display to none?
I have a pretty great SqlDataReader wrapper in which I can map the output into a strongly typed list.
What I am finding now is that on larger datasets with larger numbers of columns, performance could probably be a bit better if I can optimize my mapping.
In thinking about this there is one section in particular that I am concerned about as it seems to be the heaviest hitter:
while (_Rdr.Read())
{
T newObject = new T();
for (int i = 0; i <= _Rdr.FieldCount - 1; ++i)
{
PropertyInfo info = (PropertyInfo)_ht[_Rdr.GetName(i).ToUpper()];
if ((info != null) && info.CanWrite)
{
info.SetValue(newObject, (_Rdr.GetValue(i) is DBNull) ? default(T) : _Rdr.GetValue(i), null);
}
}
_en.Add(newObject);
}
_Rdr.Close();
What I would really like to know, is if there is a way that I can make this loop asyncronous? I feel that will make all the difference in the world with this beast :)
Here is the entire Map method in case anyone can see where I can make further improvements on it...
IList<T> Map<T>
// Map our datareader object to a strongly typed list
private static IList<T> Map<T>(IDataReader _Rdr) where T : new() {
try {
Type _t = typeof(T);
List<T> _en = new List<T>();
Hashtable _ht = new Hashtable();
PropertyInfo[] _props = _t.GetProperties();
Parallel.ForEach(_props, info =>
{
_ht[info.Name.ToUpper()] = info;
});
while (_Rdr.Read())
{
T newObject = new T();
for (int i = 0; i <= _Rdr.FieldCount - 1; ++i)
{
PropertyInfo info = (PropertyInfo)_ht[_Rdr.GetName(i).ToUpper()];
if ((info != null) && info.CanWrite)
{
info.SetValue(newObject, (_Rdr.GetValue(i) is DBNull) ? default(T) : _Rdr.GetValue(i), null);
}
}
_en.Add(newObject);
}
_Rdr.Close();
return _en;
}catch(Exception ex){
_Msg += "Wrapper.Map Exception: " + ex.Message;
ErrorReporting.WriteEm.WriteItem(ex, "o7th.Class.Library.Data.Wrapper.Map", _Msg);
return default(IList<T>);
}
}
I'm trying to display the picture associated with a user in my database (the picture field's data type is image) on a page - unfortunately the code below fails to do that.
HTML
<img src="/User/Picture/1" />
Controller Action
public byte[] Picture(int id){
UserRepository r = new UserRepository();
return r.Single(id).logo.ToArray();
}
class a(object):
c=b()# how to call the b method
d=4
def __init__(self):
print self.c
def b(self):
return self.d+1
a()
how to call the 'b' method not in the __init__
thanks
the error is :
Traceback (most recent call last):
File "D:\zjm_code\a.py", line 12, in <module>
class a(object):
File "D:\zjm_code\a.py", line 13, in a
c=b()# how to call the b method
NameError: name 'b' is not defined
I see that this question has been asked a lot, however I haven't found anything yet that solves the problem I'm having.
Obviously i'm using the Entity Framework to perform an update to a record. Once the updates are complete, however, whenever I try to save I get the following error message:
An object with the same key already exists in the objectstatemanager
At first I was passing in a collection object from the view that contained a copy of the the ZipCodeTerritory model object zipToUpdate. I changed the code by pulling this object out and just sending in the relevant fields instead. However, I'm still getting the same error.
What's also weird is the first time I run this code, it works fine. Any attempt after that I get the error.
Controller
Here is the code from the method calling the edit function
public static string DescriptionOnly(ZipCodeIndex updateZip)
{
if (!string.IsNullOrWhiteSpace(updateZip.newEffectiveDate) || !string.IsNullOrWhiteSpace(updateZip.newEndDate))
{
return "Neither effective or end date can be present if updating Territory Code only; ";
}
_updated = 0;
foreach (var zipCode in updateZip.displayForPaging.Where(x => x.Update))
{
ProcessAllChanges(zipCode, updateZip.newTerritory, updateZip.newStateCode, updateZip.newDescription, updateZip.newChannelCode);
}
_msg += _updated + " record(s) updated; ";
return _msg;
}
And here is the method that actually does the updating.
private static void ProcessAllChanges(ZipCodeTerritory zipToUpdate, string newTerritory, string newStateCode, string newDescription,
string newChannelCode)
{
try
{
if (!string.IsNullOrWhiteSpace(newTerritory)) zipToUpdate.IndDistrnId = newTerritory;
if (!string.IsNullOrWhiteSpace(newStateCode)) zipToUpdate.StateCode = newStateCode;
if (!string.IsNullOrWhiteSpace(newDescription)) zipToUpdate.DrmTerrDesc = newDescription;
if (!string.IsNullOrWhiteSpace(newChannelCode)) zipToUpdate.ChannelCode = newChannelCode;
if (zipToUpdate.EndDate == DateTime.MinValue) zipToUpdate.EndDate = DateTime.MaxValue;
_db.Entry(zipToUpdate).State = EntityState.Modified;
_db.SaveChanges();
_updated++;
}
catch (DbEntityValidationException dbEx)
{
_msg += "Error during update; ";
EventLog.WriteEntry("Monet", "Error during ProcessAllChanges: " + zipToUpdate.ToString() + " |EX| " + dbEx.Message);
}
catch (Exception ex)
{
_msg += "Error during update; ";
EventLog.WriteEntry("Monet", "Error during ProcessAllChanges: " + zipToUpdate.ToString() + " |MESSAGE| " + ex.Message);
}
}
EDIT
The ZipCodeIndex object contains a list of ZipCodeTerritory model objects. These aren't being pulled from a linq query, but instead simply passed back to the controller from the view. Here is the signature of the controller method that starts the process:
[HttpPost]
public ActionResult Update(ZipCodeIndex updateZip, string button)
Is it possible to cancel an event from within the onKey method. I only want to allow numbers 0 through 9. If another key was pressed then I want to cancel the key press
public boolean onKey(View v, int keyCode, KeyEvent ev) {
// TODO Auto-generated method stub
if(keyCode <30 || keyCode > 39){
//Cancel Event
}
return false;
}
Is there a way to have a function raise an error if it takes longer than a certain amount of time to return? I want to do this without using signal (because I am not in the main thread) or by spawning more threads, which is cumbersome.
I am trying to make a javascript function (although jquery is perfectly OK) that will return a number that corresponds to the number of checkboxes checked in a form. Seems simple enough but I can't figure out a good way of doing it.
Thanks.
Hi,
i call a controller action in a unit test.
ViewResult result = c.Index(null,null) as ViewResult;
I cast the result to a ViewResult, because that is what i'm returning in the controller:
return View(model);
But how can i access this model variable in my unit test?
I'm trying to produce some Ruby code that will take a string and return a new one, with a number x number of characters removed from its end - these can be actual letters, numbers, spaces etc.
Ex: given the following string
a_string = "a1wer4zx"
I need a simple way to get the same string, minus - say - the 3 last digits. In the case above, that would be "a1wer". The way I'm doing it right now seems very convoluted:
an_array = a_string.split(//,(a_string.length-2))
an_array.pop
new_string = an_array.join
Any ideas?
Reading the syntax from autohotkey, I am trying to achieve this. But the first step of selecting the entire line is not working:-
F5::
send {Shift Home}
return
I have tried few others too, but its not working. This is not sending Shift+Home combination on pressing F5 key.
Please tell me what's wrong with this?
Also if possible, what to do next?, as if I will write
send {F5}
I believe, it will recursively fire this script again and again..
Is there a way for a property to access its own name and type at runtime using reflection? I want to access this info without hard coding the name or index of the property in the class.
Simple Example Code:
Private ReadOnly Property MyProperyName() As String
Get
Console.WriteLine((Get Current Property Info).Type.ToString)
Console.WriteLine((Get Current Property Info).Name)
Return ""
End Get
End Property
Expected output:
System.String
MyPropertyName
//
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()) {
case EXIT:
try {
this.finish();
} catch(Exception e) {
}
break;
}
return false;
}
When I exit my android application it resumes the previous screen. How can I exit the Android application properly?
Hi everyone.
I want to search my link on other pages by passing url address.
After passing the url it should return some boolean value which will define the existence of my link.
Preferred language ASP.net/C#
If it is possible, Please help me.
In C++, the common practice is to declare functions in header files and define them in cpp files. This leads to always having two copies of every function's prototype. Then whenever I want to change a function's name/return value/parameter, I have to manually change it in both files. This seems unnecessarily tedious and there must be lots of people that share my pain, so is there a way to automate these changes between files in VS?
Bonus points for vim solutions as well.
say suppose I have class as :
public class Age {
private int age;
public int getAge() {
return this.age;
}
}
In my Main class I am calling the getAge() method many times.
So I wanted to know is it advisable to call so many times or call once and assign it to some variable and use that variable.
Which is best and why?
I cant seem to send an email using PHP's mail(). I have also tried PHPMailer and Swiftmail with no success. However, the following command on the server delivers mail successfully.
cat test.txt | mail -s "test mail" [email protected]
Is there a way to trace where the problem is coming from? mail() just seems to return true or false.
Using hibernate with annotations, i want a one-many relationship to be sorted by the 'created' field on the 'many' table.
So far i've got this, which always ends up in a random order:
// The notes
@OneToMany
@JoinColumn(name="task_id")
Set<TaskNote> notes;
public Set<TaskNote> getNotes() {return notes;}
public void setNotes(Set<TaskNote> notes) {this.notes = notes;}