Thursday, 3 October 2013

Configuring firewalld on a router, how to allow FORWARDing?

Configuring firewalld on a router, how to allow FORWARDing?

I've just installed Fedora 19 and I'm using firewalld instead of iptables,
but I'm having difficulty interpretting the new terminology.
I have 2 NICs. One is specificed ZONE="internal" and the other "external"
in the ifcfg-* files, I have set ipv4.forwarding = 1 in /etc/sysctl.conf,
and run firewall-cmd --zone=external --add-masquerade
However, when I attempt to route from any machine on the internal network
I'm getting Destination Host Prohibited and of course if I disable
firewalld the error goes away but then I lose masquerading.
In iptables there was a ruleset called FORWARD, but in firewalld I can
only find --add-port-forward which isn't the same thing.
How do I allow routing in firewalld ?
TIA.

Wednesday, 2 October 2013

not get the android map V2 in emulator

not get the android map V2 in emulator

10-03 02:03:53.220: W/GooglePlayServicesUtil(841): Google Play services
out of date. Requires 3265100 but found 2012110 10-03 02:03:53.240:
W/GooglePlayServicesUtil(841): Google Play services out of date. Requires
3265100 but found 2012110 10-03 02:03:53.260:
W/GooglePlayServicesUtil(841): Google Play services out of date. Requires
3265100 but found 2012110 10-03 02:03:53.270:
W/GooglePlayServicesUtil(841): Google Play services out of date. Requires
3265100 but found 2012110 10-03 02:03:53.290:
W/GooglePlayServicesUtil(841): Google Play services out of date. Requires
3265100 but found 2012110 10-03 02:03:53.330:
W/GooglePlayServicesUtil(841): Google Play services out of date. Requires
3265100 but found 2012110 10-03 02:03:53.330: D/AndroidRuntime(841):
Shutting down VM 10-03 02:03:53.341: W/dalvikvm(841): threadid=1: thread
exiting with uncaught exception (group=0x40a71930) 10-03 02:03:53.360:
E/AndroidRuntime(841): FATAL EXCEPTION: main 10-03 02:03:53.360:
E/AndroidRuntime(841): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{info.tekguc.umut.googlemapsmapsandroidv2/info.tekguc.umut.googlemapsmapsandroidv2.MainActivity}:
java.lang.NullPointerException 10-03 02:03:53.360: E/AndroidRuntime(841):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-03 02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-03 02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread.access$600(ActivityThread.java:141) 10-03
02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 10-03
02:03:53.360: E/AndroidRuntime(841): at
android.os.Handler.dispatchMessage(Handler.java:99) 10-03 02:03:53.360:
E/AndroidRuntime(841): at android.os.Looper.loop(Looper.java:137) 10-03
02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread.main(ActivityThread.java:5041) 10-03
02:03:53.360: E/AndroidRuntime(841): at
java.lang.reflect.Method.invokeNative(Native Method) 10-03 02:03:53.360:
E/AndroidRuntime(841): at java.lang.reflect.Method.invoke(Method.java:511)
10-03 02:03:53.360: E/AndroidRuntime(841): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-03 02:03:53.360: E/AndroidRuntime(841): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 10-03
02:03:53.360: E/AndroidRuntime(841): at
dalvik.system.NativeStart.main(Native Method) 10-03 02:03:53.360:
E/AndroidRuntime(841): Caused by: java.lang.NullPointerException 10-03
02:03:53.360: E/AndroidRuntime(841): at
info.tekguc.umut.googlemapsmapsandroidv2.MainActivity.onCreate(MainActivity.java:23)
10-03 02:03:53.360: E/AndroidRuntime(841): at
android.app.Activity.performCreate(Activity.java:5104) 10-03 02:03:53.360:
E/AndroidRuntime(841): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-03 02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-03 02:03:53.360: E/AndroidRuntime(841): ... 11 more 10-03 02:03:53.360:
E/AndroidRuntime(841): FATAL EXCEPTION: main 10-03 02:03:53.360:
E/AndroidRuntime(841): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{info.tekguc.umut.googlemapsmapsandroidv2/info.tekguc.umut.googlemapsmapsandroidv2.MainActivity}:
java.lang.NullPointerException 10-03 02:03:53.360: E/AndroidRuntime(841):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-03 02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-03 02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread.access$600(ActivityThread.java:141) 10-03
02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 10-03
02:03:53.360: E/AndroidRuntime(841): at
android.os.Handler.dispatchMessage(Handler.java:99) 10-03 02:03:53.360:
E/AndroidRuntime(841): at android.os.Looper.loop(Looper.java:137) 10-03
02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread.main(ActivityThread.java:5041) 10-03
02:03:53.360: E/AndroidRuntime(841): at
java.lang.reflect.Method.invokeNative(Native Method) 10-03 02:03:53.360:
E/AndroidRuntime(841): at java.lang.reflect.Method.invoke(Method.java:511)
10-03 02:03:53.360: E/AndroidRuntime(841): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-03 02:03:53.360: E/AndroidRuntime(841): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 10-03
02:03:53.360: E/AndroidRuntime(841): at
dalvik.system.NativeStart.main(Native Method) 10-03 02:03:53.360:
E/AndroidRuntime(841): Caused by: java.lang.NullPointerException 10-03
02:03:53.360: E/AndroidRuntime(841): at
info.tekguc.umut.googlemapsmapsandroidv2.MainActivity.onCreate(MainActivity.java:23)
10-03 02:03:53.360: E/AndroidRuntime(841): at
android.app.Activity.performCreate(Activity.java:5104) 10-03 02:03:53.360:
E/AndroidRuntime(841): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-03 02:03:53.360: E/AndroidRuntime(841): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-03 02:03:53.360: E/AndroidRuntime(841): ... 11 more 10-03 02:03:56.960:
I/Process(841): Sending signal. PID: 841 SIG: 9

WMI query and event works in single class but not application?

WMI query and event works in single class but not application?

I am using WMI to find events where a USB device is plugged in. I made a
standalone class to try this out, and it worked great! As soon as I call
the class from my application, it does not work. The code is identical,
with the exception of the main() when I compile the class as a stand-alone
exe. The code follows:
ManagementScope scope = new ManagementScope("root\\CIMV2"); //set the
scope
WqlEventQuery query = new WqlEventQuery("SELECT * FROM
__InstanceCreationEvent WHERE TargetInstance ISA 'Win32_PnPEntity'");
//set the events
watcher = new ManagementEventWatcher(scope, query);
watcher.EventArrived += new
EventArrivedEventHandler(this.DeviceChangeEventReceived);
watcher.Start();
The DeviceChangeEventReceived method is never called when built into the
larger application. I thought it might be the scope, but it seems not to
be. I am sure that it's something simple, but I'm out of ideas. Thanks!

Vector of pairs or pair of vectors?

Vector of pairs or pair of vectors?

In my code I'm dealing with a set of measurements (a vector of float), in
which each element has two associated uncertainties (say +up/-down). Let's
say I want to dump on screen these values, something like
Loop over the vector of the measurements
{
cout << i-th central value << " +" << i-th up uncertainty << " / -" <<
i-th down uncertainty << end;
}
What's the most efficient/elegant way to do it?
1) Using a pair of vectors
vector<float> central; //central measurement
pair<vector<float>, vector<float>> errors; //errors
for( int i = 0; i < central.size ; i++ )
{
cout << central.at(i) << " +" << errors.first.at(i) << " / -" <<
errors.second.at(i) << endl;
}
2) Using a vector of pairs:
vector<float> central; //central measurement
vector<pair<float,float>> errors; //errors
for( int i = 0; i < central.size ; i++ )
{
cout << central.at(i) << " +" << errors.at(i).first << " / -" <<
errors.at(i).second << endl;
}
3) Two separate vectors:
vector<float> central; //central measurement
vector<float> errUp; //errors up
vector<float> errDown; //errors down
for( int i = 0; i < central.size ; i++ )
{
cout << central.at(i) << " +" << errUp.at(i) << " / -" <<
errDown.at(i) << endl;
}

Web mobile upload using C#

Web mobile upload using C#

i'm trying to develop a web mobile app using C#. its just a simple upload
picture module, and get its exif. the app is working fine on normal
browser on PC. file can be upload and exif can be read.
however when tested on most mobile browsers, this exception was thrown:
'Could not find a part of the path 'c:\inetpub\wwwroot\Temp\1.jpg'.
here's the line in .aspx file
<input id="imgUpload" type="file" runat="server" />
and the lines in .aspx.cs file
string filename = myProfile.ID.ToString() + ".jpg";
string physiclPath = HttpContext.Current.Server.MapPath("..\\..\\Temp\\");
imgUpload.PostedFile.SaveAs(physiclPath + filename);
Response.Write("File uploaded successfully!");
is there anything important i miss for web mobile uploads?

Tuesday, 1 October 2013

Advice with range function and or statements python

Advice with range function and or statements python

I am just trying to add up all the multiples of 3 and 5 up to 1000, while
making sure that I do not add the coinciding multiples twice hence the or.
I only want it to add the multiple of 5 if it is not a multiple of 3.
Thanks in advance
a=range(0, 1000,3 ) or range(0,1000,5)
b=sum(a)
print (b)

Cookies wont set if i specify an expiry date

Cookies wont set if i specify an expiry date

this works:
setcookie('$id', $date);
But this doesnt set a cookie:
setcookie('$id', $date, 1000);
Any ideas?