Hi, I'm reading "Pro Javascript Techniques" from John Resig, and I'm confused with an example. This is the code:
// Create a new user object that accepts an object of properties
function User( properties ) {
// Iterate through the properties of the object, and make sure
// that it's properly scoped (as discussed previously)
for ( ...
I have a piece of code here that i really could use some help with refactoring. I need the different methods for adding relational data in a form in rails. The code is taken from http://railscasts.com/episodes/75-complex-forms-part-3, my problem is that i need to have the methods fro both the Material model and the Answer model. So i nee...
I am trying to add the following method to the Math class in Ruby on Rails:
class Math
def self.round_with_precision(number, precision)
scalar = 10.0 ** precision
number = number * scalar
number = number.round
number = number / scalar
return number;
end
end
I then added the following to my environment.rb:
requ...
For instance, is the following possible:
#define definer(x) #define #x?
Thanks.
...
I am trying to write a javascript class that loads script files as they are needed. I have most of this working. It is possible to use the library with the following Syntax:
var scriptResource = new ScriptResource('location/of/my/script.js');
scriptResource.call('methodName', arg1, arg2);
I would like to add some additional syntactic ...
Consider type like this one
public interface IHaveGenericMethod
{
T1 Method<T1>(T1 parm);
T2 Method<T1,T2>(T1 parm);
int Method2(int parm);
}
How do I get a methodInfo for its methods?
for a regular non-generic method, like method2, I can go with
typeof(IHaveGenericMethod).GetMethod("methodName",new Type[]{typeof(itsParamete...
I have a class with some methods. It's supersekret but I've reproduced what I can here.
Class RayGun
# flashes red light
# requires confirmation
# makes "zowowowowowow" sound
def stun!
# ...
end
# flashes blue light
# does not require confirmation
# makes "trrrtrtrtrrtrtrtrtrtrtr" sound
def freeze!
# ...
end...
Hello,
Do you know about a library that allows us to generate UI by just stating that it should be generated?
I think there must be a person who have implemented a mechanism allowing us to transform code like this:
class Main {
@Command
int add(int a, int b) {
return a+b;
}
}
into, say, a dialog with 2 text fields...
What is the best tutorial, recipe, how-to, to embed a scripting language (like python, lua...) in another language (like c#)? Particularly, one that shows how to provide host-level elements in the script-level language (e.g. whenever someone accesses the attribute name of the object 'car' in python, the host application intercepts that c...
I ask about the pattern, not framework. This is kind of follow-up to a question on UI auto-generation.
Do you believe in the concept of UI auto-generation from metadata?
What kind of problems can be approached this way?
The question arose when I've created a small library to support my student projects, which generates interactive CL...
Is there a way that I can create a function that takes an int template parameter, and have that function give a compile time error if the value passed to the function is less than 10?
The following code does not work, but it shows what I want to accomplish:
template <int number1>
void reportErrorIfLessThan10()
{
#if(number1 < 10)
...
Was the year before that 0 CE or 1 BCE?
This is a meta-programming question, relating to the religious wars over the first number in a list. Should it be 0 or 1?
Some points to consider:
What would Richard Stallman say? I read an article by him recently where he got upset that the OLPC is offering Windows. He listed the reasons th...
Is it possible to auto-discover parameters to shell/Perl scripts in order to "meta" program WEB UIs for them?
I have a bunch of "legacy" scripts that I'd like to "web wrap".
So far I have created a CGI-BIN web app with about 3 parameters that can call a bash/Perl reporting script.
But it now occurs to me maybe there is quicker or aut...
As developers, we have to constantly learn about new languages and technologies.
What did you do to learn the programming languages (or frameworks) you know now? Please list
Programming language or framework
Resource
Either web page
or
Book
Did you have any special projects for that language / Can you recommend a project to learn tha...
I have a bunch of Python modules in a directory, all being a derivate class. I need a "runner" script that, for each module, instantiate the class that is inside it (the actual class name can be built by the module file name) and than call the "go" method on each of them.
I don't know how many modules are there, but I can list all of th...
I recently discovered metaclasses in python.
Basically a metaclass in python is a class that creates a class. There are many useful reasons why you would want to do this - any kind of class initialisation for example. Registering classes on factories, complex validation of attributes, altering how inheritance works, etc. All of this be...
I was reading an article on TheServerSide on ployglot programming on the Java platform. Some comments in the article refer to metaprogramming as the ability to generate code (perhaps on the fly).
Is metaprogramming the ability to generate code on the fly or is it the ability to inject methods and attributes into existing objects at run...
Hello,
I need to generate code for a method at runtime. It's important to be able to run arbitrary code and have a docstring.
I came up with a solution combining exec and setattr, here's a dummy example:
class Viking(object):
def __init__(self):
code = '''
def dynamo(self, arg):
""" dynamo's a d...
Using Groovy's package name convention, I can intercept Groovy method calls to a Java method like so:
package groovy.runtime.metaclass.org.myGang.myPackage
class FooMetaClass extends groovy.lang.DelegatingMetaClass
{
StringMetaClass(MetaClass delegate)
{
super(delegate);
}
public Object getProperty(Object a, St...
I'd like to implement a Rails User model that has a DB column called password. I want to make it so that when I call...
user_instance.password = 'cleartext'
the method hashes the cleartext before setting it on the instance like so:
Digest::SHA1.hexdigest(cleartext)
I've tried using a callback, but the problem is that is hashes the ...