Hi, hereafter is my piece of code that I want to simplify in order to avoid passing an extra argument on each call :
module M
def do_something(context)
puts "Called from #{context}"
end
module_function :do_something
end
class Foo
def do_stuff
M.do_something(self)
end
end
Foo.new.do_stuff
Is there a way to do the same think without passing 'self' as an input argument to 'do_something' method like this ?
module M
def do_something
puts "Called from #{method that returns caller object}"
end
module_function :do_something
end
class Foo
def do_stuff
M.do_something
end
end
Foo.new.do_stuff
Thanks for your support!
Hi,
I am not so good with regex. I am struggling to find a solution for a small functionality.
I have a ajax response which returns a string like "Your ticket has been successfully logged. Please follow the link to view details 123432."
All I have to do is replace that number 123432 with <a href="blablabla.com?ticket=123432"> using javascript.
Say you have data in the format:
name=john;age=33;gender=male
How would you call a method that converts data like that into an an object / associative array?
I've been thinking about:
- unserialize_variables
- parse_variables
I want to break the following string at the word To and then truncate the email address that follows at 15 characters using JavaScript. This is the sentence:
Please email this card to[email protected]
It should like like this:
Please email this card
to email@emailadd...
Hi All,
I have following:
temp = "aaaab123xyz@+"
lists = ["abc", "123.35", "xyz", "AND+"]
for list in lists
if re.match(list, temp, re.I):
print "The %s is within %s." % (list,temp)
The re.match is only match the beginning of the string, How to I match substring in between too.
We have some legacy string dates that I need to convert to actual dates that can be used to perform some date logic. Converting to a date object isn't a problem if I knew what the format were! That is, some people wrote 'dd month yy', othes 'mon d, yyyy', etc.
So, I was wondering if anybody knew of a py module that attempts to guess date formats and rewrites them in a uniform way?
Any other suggestions?
Thanks! :)
Eric
Hi All,
(Yesterday, I had a question about cross section. Sorry due to repeating the question. I could not use the "edit" property of the page since it was not available on the screen.)
Could one explain me how to have the points that are on the intersection curve of a 3d mesh object and a plane.
Regards
J.Jack
Is there anybody who can help me making pixels of an png picture transparant, such like: MakePixelTransparant(const png:TPngImage; x,y:integer; perc:integer); and what else do I have to do to makes thinks works (with values do i have to change to make the png object transparant, so i can use it in for example PhotoShop).
Thanks, John Duinmeijer.
Is there a way to convert a date to a string in Sqlite? For example I am trying to get the min date in Sqlite:
SELECT MIN(StartDate) AS MinDate FROM TableName
I know in SQL Server I would use the SQL below to accomplish what I am trying to do:
SELECT CONVERT(VARCHAR(10), MIN(StartDate), 101) AS MinDate FROM TableName
Thanks!
How can I parse a pubDate from a RSS feed to a Date object in java.
The format in the RSS feed:
Sat, 24 Apr 2010 14:01:00 GMT
What I have at the moment:
DateFormat dateFormat = DateFormat.getInstance();
Date pubDate = dateFormat.parse(item.getPubDate().getText());
But this code throws an ParseException with the message Unparseable date
I'm getting strange error "'int' object has no attribute 'startswith'"
I haven't used the word "startswith" in my python program. ?
Does any one how to fix this -- or what it refers to ?
When should object literals be used in javascript, sometimes I get confused I am trying to apply oop concepts and pattern to the language. I am trying to not just use procedural programming concepts because I know the language has amazing capabilities.
I am trying to become more familiar with using the builtin string matching stuff available in shells in linux. I came across this guys posting, and he showed an example
a="abc|def"
echo ${a#*|} # will yield "def"
echo ${a%|*} # will yield "abc"
I tried it out and it does what its advertised to do, but I don't understand what the $,{},#,*,| are doing, I tried looking for some reference online or in the manuals but I couldn't find anything. Can anyone explain to me what's going on here?
hi guys,
i am wondering is there a convenient function in rails to convert string with negative signs into a number. e.g. -1005.32
when i use to_f method, the number will simply become 1005 with the negative sign and decimal part being ignored.
thanks in advance!
I have a few classes: SomeClass1, SomeClass2.
How can I create a new instance of one of these classes by using the class name from a string?
Normally, I would do:
var someClass1 = new SomeClass1();
How can I create this instance from the following:
var className = "SomeClass1";
I am assuming I should use Type.GetType() or something but I can't figure it out.
Thanks.
How could I select all as one string seperated with a ,?
Example table:
Table
Stringtest
Examplestring2
Anotherstring
Otherstring
And the selected result should be Stringtest,Examplestring2,Anotherstring,Otherstring.
Hi,
I am trying to extract the field 'name' or 'named-expr' from the following object:
(bind 'x (num 5)) ;; note that this is not a list, but a type Binding
With the Binding definition:
(define-type Binding
(bind (name symbol?) (named-expr WAE?)))
I have tried, but received the error "reference to an identifier before its definition: Binding-name." Here is what I tried typing:
(begin (Binding-name (bind 'x (num 5))))
(begin (define x (bind 'x (num 5))) (Binding-name x))
Thank you!
I was wondering if PHPStorm by Jetbrains has a tool to sort the methods in my JavaScript object by name. If not are there any other tools that can do this for me?
Ext.regController("dashboard", {
goToShoppingCart:function() {
Ext.dispatch({
controller:"shoppingCart",
action:"loadCart"
});
},
goToDashboard:function() {},
goToContact:function() {}
}
);
to
Ext.regController("dashboard", {
goToContact:function() {},
goToDashboard:function() {},
goToShoppingCart:function() {
Ext.dispatch({
controller:"shoppingCart",
action:"loadCart"
});
}
}
);
This is only for organization.
Thanks
Having a class like this:
class Spam(object):
def __init__(self, name=''):
self.name = name
eggs = Spam('systempuntoout')
Using dis, is it possible to see how an instance of a class and the rispective identity are created?
In Java how to test if a Collection of objects contains an object depending on one of its properties.
For example I would like to test if Collection<myObjects> contains an instance of myObjects which has myObjects.name = "myName".
Working with COM interop, I can call a managed function from within unmanaged code.
But, this only gives me the HRESULT for the exception, in case a managed exception is thrown.
Is there anyway to further inspect the exception from the unmanaged code? For example, to look at the message contained in the exception object.
Thanks!
I've got some analysis code (myprog) that sucks in data using the following:
if(5 == fscanf(in, "%s%lf%f%f%f", tag, & sec, & tgt, & s1, & s2))
which works just fine. But in the situation where I've got data files that are separated by commas, I'm currently doing something like:
sed 's/,/ /g' data | myprog
Can I modify the format string in the fscanf() function to accept both delimitation formats?
Let's say I have an object who's class definition looks like:
class Command:
foo = 5
def run(self, bar):
time.sleep(1)
self.foo = bar
return self.foo
If this class is instantiated once, but different threads are hitting its run method (via an HTTP request, handled separately) passing in different args, what is the best method to queue them? Can this be done in the class definition itself?