Im trying to dynamically create a method chain in one attribute in my model.
By now I have this function:
def create_filtered_attribute(attribute_name)
alias_attribute "#{attribute_name}_without_filter", attribute_name
define_method "#{attribute_name}" do
filter_words(self.send("#{attribute_name}_without_filter"))
end
end
so I receive a string with the attribute name, alias it for '*_without_filter*' (alias_method or alias_method_chain fails here, because the attribute isnt there when the class is created),
and I create a new method with the attribute name, where I filter its contents.
But somehow, when I call *"#{attribute_name}_without_filter"* it calls my new method (i think because the alias_attribute some how), and the program goes into a stack loop.
Can someone please enlighten me on this.
I'm not sure if this is possible, and I'm quite new to using assemblies in C#.NET.
What I would like to do is to create an instance of a class when supplied the string name of that class. Something like this:
using MyAssembly;
namespace MyNameSpace
{
Class MyClass
{
int MyValue1;
int MyValue2;
public MyClass(string myTypeName)
{
foreach(Type type in MyAssembly)
{
if((string)type == myTypeName)
{
//create a new instance of the type
}
}
AssignInitialValues(//the type created above)
}
//Here I use an abstract type which the type above inherits from
private void AssignInitialValues(AbstractType myClass)
{
this.value1 = myClass.value1;
this.value2 = myClass.value2;
}
}
}
Obviously you cannot compare strings to types but it illustrates what I'm trying to do: create a type from a supplied string.
Any thoughts?
EDIT:
After attempting:
var myObject = (AbstractType) Activator.CreateInstance(null, myTypeName);
AssignInitialValues(myObject);
I get a number of errors:
Inconsistent accessibility: parameter type 'MyAssembly.AbstractType' is less accessible than method 'MyNameSpace.MyClass.AssignInitialValues(MyAssembly.AstractType)'
'MyAssembly.AstractType' is inaccessible due to it's protection level
The type or namespace name 'MyAssembly' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'AbstractType' could not be found (are you missing a using directive or an assembly reference?)
Not exactly sure why it can't find the assembly; I've added a reference to the assembly and I use a Using Directive for the namespace in the assembly. As for the protection level, it's calling classes (or rather the constructors of classes) which can only be public.
Any clues on where the problem is?
UPDATE:
After looking through several articles on SO I came across this: http://stackoverflow.com/a/1632609/360627
Making the AbstractTypeclass public solved the issue of inconsistent accessibility.
The new compiler error is this:
Cannot convert type 'System.Runtime.Remoting.ObjectHandle' to 'MyAssembly.AbstractType'
The line it references is this one:
var myObject = (AbstractType) Activator.CreateInstance(null, myTypeName);
Using .Unwrap() get's me past this error and I think it's the right way to do it (uncertain). However, when running the program I then get a TypeLoadException when this code is called.
TypeLoadException: Could not load type ‘AbstractType’ from assembly ‘MyNameSpace'...
Right away I can spot that the type its looking for is correct but the assembly it's looking in is wrong. Looking up the Activator.CreateInstance(String, String) method revealed that the null as the first argument means that the method will look in the executing assembly. This is contrary to the required behavior as in the original post.
I've tried using MyAssembly as the first argument but this produces the error:
'MyAssembly' is a 'namespace' but is used like a 'variable'
Any thoughts on how to fix this?
In the App ID section of the Program Portal, locate the App ID you wish to use with the Apple Push Notification service. Only App IDs with a specific bundle ID can be used with the APNs. You cannot use a “wild-card” application ID. You must see “Available” under the Apple Push Notification service column to register this App ID and configure a certificate for this App ID.
Click the ‘Configure’ link next to your desired App ID.
In the Configure App ID page, check the Enable Push Notification Services box and click the Configure button. Clicking this button launches the APNs Assistant, which guides you through the next series of steps that create your App ID specific Client SSL certificate.
Download the Client SSL certificate file to your download location. Navigate to that location and double-click the certificate file (which has an extension of cer) to install it in your keychain.
When you are finished, click Done in the APNS Assistant.
Double-clicking the file launches Keychain Access. Make sure you install the certificate in your login keychain on the computer you are using for provider development. The APNs SSL certificate should be installed on your notification server.
When you finish these steps you are returned to the Configure App ID page of the iPhone Dev Center portal. The certificate should be badged with a green circle and the label “Enabled”.
To complete the APNs set-up process, you will need to create a new provisioning profile containing your APNs-enabled App ID.
IS it posssible to do theses steps through code.
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#define IE 40
#define JE 40
#define KE 40
#define ia 7
#define ja 7
#define ka 7
#define NFREQS 3
using namespace std;
main()
float l,m,n,i,j,k,ic,jc,kc,nsteps,n_pml;
float ddx,dt,T,epsz,muz,pi,eaf,npml;
int ib,jb,kb;
.
.
.
.
ic=IE*0.5 ;
jc=JE*0.5 ;
....'ic'dose not name a type.
....'jc'dose not name a type.
Has anyone found a solution to decompressing RAR files on iPhone (not Jailbroken)? It would be great if there was a library similar to libz.
I did not find anything official from [URL="http://www.rarlab.com/"]RARlab[/URL].
Anyone successful with integrating [URL="http://wdtz.org/iphone/unrar/"]unRAR[/URL] into their app? The
source code appears to be C++?
I know that this has been asked before, but I've not seen a solution other than porting unRAR which is beyond me. Would greatly appreciate any information or suggestions. Thank you.
Hello,
I want to set my GtkComboBox to have some default name on it as follows:
+---------------+---+
| Image Options | X |
+---------------+---+
| Image Option 1 |
+-------------------+
| Image Option 2 |
+-------------------+
| Image Option 3 |
+-------------------+
Thanks,
PP.
Hello,
I've downloaded Eclipse Classic 3.5 Galileo, the last version of Android SDK, downloaded and installed Eclipse Android 1.6 platform.
I've created first (and the only) AVD with Android 1.6 and the default skin.
The log may show more:
I've filtered only neccessary messages (warnings, errors).
-http://www.clipboard.cz/63c
As you can see, my new AVD has started in 16:17 and it was still loading in 17:35...
The emulator looks like this:
http://img130.imageshack.us/img130/3540/androidloading.png
PS: The restrictions about number of links for new accounts are REALLY annoying...
When I use
<%= link_to image_tag("foo.png"), home_path %>
and display it on my localhost on my iPhone, it's broken. When I inspect on with firebug, the src of the image is http://localhost:3000/images/foo.png thus causing it to break on my iPhone.
When I use
<img src="/images/foo.png" />
it displays fine on my iPhone. I am pointing to the IP address of my PC running the server of my rails app in Safari. It's loading the text but all the css, JavaScript, and images are missing unless the path is absolute with using the rails default helpers.
Is there a way to correct this path issue locally so it's absolute like /images/foo.png instead of http://localhost:3000/images/foo.png.
Update
CSS file paths are also affected. Instead of just making the path /stylesheets/foo.css, it's http://localhost:3000/stylesheets/foo.css.
Update: Solution
It's the Facebook plugin changing the asset host to the callback url of my facebook app settings which is currently set to http://localhost:3000/
So, throughout my entire document, I would like for every single time the user hovers over an element with a specific class name, I would like a class to be added.
My CSS looks like this:
.hotspot:hover, .hotspothover
{
border: 4px solid #fff;
box-shadow: 0px 0px 20px #000;
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
z-index: 1;
}
Class name: "hotspot".
I tried this, but it doesn't seem to work:
$("#hotspot.hover #hotspothover").addClass("bubble bottom");
Thanks.
I want to write a SQL 2005 script to create a new login that uses Windows authentication. The Windows user is a local account (not a domain one). A local account with the same name exists on many SQL Server machines and I want to run the same script on all of them.
It seemed simple enough:
CREATE LOGIN [MyUser]
FROM WINDOWS
However, that doesn't work! SQL returns an error, saying Give the complete name: <domain\username>.
Of course, I can do that for one machine and it works, but the same script will not work on other machines.
I have a simple Java program which reads a file directory and outputs a file list.
I sort the files by name:
String [] files = dirlist.list();
files = sort(files);
My problem is that it sorts by name in a different way than Windows Explorer does.
For instance if I have these files: abc1.doc, abc12.doc, abc2.doc.
Java will sort like this:
abc1.doc
abc12.doc
abc2.doc
When I open the folder in Explorer, my files are sorted like this:
abc1.doc
abc2.doc
abc12.doc
How can I make Java sorts my files like in Windows Explorer?
Is this a Windows trick?
Hello,
What are the ways to communicate with a kernel module from user space? By communication i mean sending information and commands between the module and a user space process.
I currently know of two way:
open/close/read/write/ioctl on published device node.
read/write on exported and hooked /proc file.
More specifically, can someone advice the best way to communicate with a kernel module that does not actually drives any hardware and therefore should not be littering /dev with stub nodes that exists solely for ioctl calls? I mostly need to check its various status variables and send it a block of data with a request type tag and see if the request succeeded.
Inso.
I would like to programmatically add to Windows a name / IP association so that this name can be resolved locally. This does not have to be persisted between reboots.
The only way I now is to add an entry to the "hosts" file, but this feels hacky especially since I would like to automate this.
Is there any way to do this using a command-line tool or a Win32 API? Perhaps by addind an entry to Windows DNS cache or something similar?
Oh, and please state if this solution is Vista-compatible.
Regards.
Edit : Thanks, guy. Sadly, all of your answers indeed involve DNS or other servers. I was looking for a purely local solution which would work on a "standard" Windows installation. Such a thing does not seem to exist, though.
I'm trying to have standard interface orientation, but without the animation.
I would like to be able to turn the iPhone and have have the view adjusted instantly.
I've seen people recommend this function, but it doesn't seem to work.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
Any help is greatly appreciated!
Thanks!
During inAppPurchase, the storeKit will ask the username and password
even though i set...
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
It ask Username and password in Portrait Mode... In general How to solve this kind of issue.
Thanks in advance,
I have a service and I want the service promote to enable it as Device Admin,
until now I launched this kind of UI interactions from the service like
Intent intent2 = new Intent();
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent2.setAction(android.content.Intent.ACTION_VIEW);
intent2.setDataAndType(uri, "application/vnd.android.package-archive");
context.startActivity(intent2);
and it works, but with DevicePolicyManager I can't find the way:
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "some text.");
context.startActivity(intent);
does't work: do not promote nothing but also do not crash. Without intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); It simply crash because this code is inside a tread inside a service. Ideas?
sTypeName = ... //do some string stuff here to get the name of the type
/*
The Assembly.CreateInstance function returns a type
of System.object. I want to type cast it to
the type whose name is sTypeName.
assembly.CreateInstance(sTypeName)
So, in effect I want to do something like:
*/
assembly.CreateInstance(sTypeName) as Type.GetType(sTypeName);
How do I do that? And, what do I take on the left side of the assignment expression, assuming this is C# 2.0. I don't have the var keyword.
I am using Activity-alias in AndroidManifest.xml to specify another entry point to my application using shortcut. I am seeing the shortcut in the shortcut list. How can I get my 2nd icon (shortcut) to show in the Home?
Hi, how can i write a regular expression to validate name field in a multilingual web application, i want to validate the name field for non-English languages e.g. Spanish or German, and we need to make sure that no one enter digits or special characters. I'm using .NET.
I believe we can't use expression as below for non-English language.
^[a-zA-Z]{1,20}$
Any help will be highly appreciated!
Solution: I'm using this regular expression
^\p{L}[\p{L}\p{Pd}\x27]*\p{L}$
, and the below MSISDN article was very helpful:
MSDN - Regular Expression
Also below tool is very helpful, in validating your regular expression:
Regex Builder
Hi,
I'm trying to dynamically create buttons at runtime with PyQT4.7
However, this being my first python program I'm not sure how to get the functionality I want.
I would like to be able to substitute a text string for an attribute name:
i.e.
for each in xrange(4):
myname = "tab1_button%s" % each #tab1_button0, tab1_button1, tab1_button2
#self.ui.tab1_button0 = QtGui.QPushButton(self.ui.tab) <--normal code to create a named button
setattr(self.ui,myname,QtGui.QPushButton(self.ui.tab)) #rewrite of line above to dynamicly generate a button
#here's where I get stuck. this code isn't valid, but it shows what i want to do
self.ui.gridLayout.addWidget(self.ui.%s) % myname
#I need to have %s be tab1_button1, tab1_button2, etc. I know the % is for string substituion but how can I substitute the dynamically generated attribute name into that statement?
I assume there's a basica language construct I'm missing that allows this. Since it's my first program, please take it easy on me ;)