Monday, May 14, 2012

iOS NSMutableString split like java's String method split()

I hava a NSString which uses $ as delimiters, e.g.



    NSMutableString *str = @"AA$BB$CC";


So, my questio is: is there a method to split that NSMutableString by delimiters '$' and store into an array,
just like in java:



    String[] list = str.split()


thanks advancde.





Meta syntax, or syntax for documenting syntax

While going through and properly documenting old code, I was wondering, what standards are there for documenting syntax?




  • regular expressions: there's no single standard, and it's a little confusing to read.

  • the one used in python documentation (here's an example): it looks nice, but I haven't been able to find the specification anywhere.



Are there any others, and which one is best?





Programmaticlly upload synonyms to google search api using java

I'm having issues figuring out how to programmaticlly upload synonyms to the google search api from my server using java.



1. The Authorization: The desciption of how to do a server to google api is explained here. Where can I find a simple example of this using java?



2. Upload synonyms: I have created the xml to be uploaded, explained here. I am not able to see how I actually upload this to the google-api. Is there an example of how this is done?





Automate text replace in Visual Studio

I have a web project that I am ripping out all the inline styling and adding it to a CSS file, and I can't help but think there is an easier way to do this.



My current process is:




  1. Search Solution for style=", if none selected, goto: 9

  2. Cut all the text between the quote marks

  3. Create new class in CSS file

  4. Paste code in class

  5. Copy class name

  6. Return to html line and paste class name in between quote marks

  7. Rename style to class

  8. goto: 1

  9. Rejoice!



I would really like to rejoice, but there seems to be a never ending supply of inline styling.



Is there a way to automate this process in Visual Studio 2010? If it requires writing a plugin, that is totally fine! I have this same task to do on many a project.



Also, I'd like to be able to do this for arbitrary tags. For example, I'm also taking all of the data-* tags and doing roughly the same thing, but adding a line of jQuery to add it back in. Something like:



$('SELECTOR').attr('data-bind','visible: IsValid');


The work is too repetitious for me not to believe there is an automated (or at least faster/better/less time consuming) way of doing this.



The project is an MVC project if that changes anything.





Arduino input fluctuates

With the following code I get a log like the one below. Why is that?



int analogPin = 5;
int val = 0;

void setup(void) {
Serial.begin(9600);
}

void loop(void) {
val = analogRead(analogPin);
Serial.print("Analog reading = ");
Serial.println(val);
}


Result:



Analog reading = 998
Analog reading = 981
Analog reading = 511
Analog reading = 159
Analog reading = 24
Analog reading = 108
Analog reading = 439
Analog reading = 946
Analog reading = 1023
Analog reading = 420
Analog reading = 116
Analog reading = 25
Analog reading = 151
Analog reading = 542
Analog reading = 997
Analog reading = 982
Analog reading = 513
Analog reading = 161
Analog reading = 25
Analog reading = 107
Analog reading = 437
Analog reading = 945
Analog reading = 1023
Analog reading = 421
Analog reading = 117
Analog reading = 25
Analog reading = 150
Analog reading = 541
Analog reading = 997
Analog reading = 983
Analog reading = 515
Analog reading = 162
Analog reading = 25
Analog reading = 107
Analog reading = 437
Analog reading = 945
Analog reading = 1023
Analog reading = 422
Analog reading = 117
Analog reading = 25
Analog reading = 149
Analog reading = 540
Analog reading = 997
Analog reading = 983
Analog reading = 516
Analog reading = 162
Analog reading = 25
Analog reading = 107
Analog reading = 436
Analog reading = 945
Analog reading = 1023
Analog reading = 422
Analog reading = 117
Analog reading = 25
Analog reading = 150
Analog reading = 540
Analog reading = 998
Analog reading = 982
Analog reading = 516
Analog reading = 162
Analog reading = 25
Analog reading = 108
Analog reading = 437


Is the result just noise?



And as soon as I plug in a cable I see the following pattern:



Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 72
Analog reading = 447
Analog reading = 1023
Analog reading = 1023
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 118
Analog reading = 849
Analog reading = 1023
Analog reading = 835
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 40
Analog reading = 401
Analog reading = 1023
Analog reading = 1023
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 0
Analog reading = 89
Analog reading = 475
Analog reading = 1023
Analog reading = 1023


Is that my heartbeat or so??? No idea what can have such an influence on a empty pin.





Adding buttons to header using css

I want to add button to following header. It should have layout like



http://www.fullstopinteractive.com/



Header CSS:



body {
margin:0;
padding:100px 0 50px 0;
}

div#header {
position:absolute;
top:0;
left:0;
width:100%;
height:30px;
background-color: #800080;
}

div#footer {
position:absolute;
bottom:0;
left:0;
width:100%;
height:50px;
background-color: #800080;
}

@media screen {
body>div#header {
position:fixed;
}

body>div#footer {
position:fixed;
}
}

* html body {
overflow:hidden;
}

* html div#content {
height:100%;
overflow:auto;
}


CSS:



#nav {
float: right;
padding: 42px 0 0 30px;
}

#nav li {
float: left;
margin: 0 0 0 5px;
}

#nav li a {
padding: 5px 15px;
font-weight: bold;
color: #ccc;
color: rgba(255, 255, 255, 0.7);
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
-webkit-border-radius: 14px;
-moz-border-radius: 14px;
border-radius: 14px;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}

#nav li a:hover, #nav li a:focus {
color: #fff;
background: rgba(255, 255, 255, 0.15);
}


HTML:



 <div id="header">  
<ul id="nav">
<li><a href="#">HOME</a></li>
<li><a href="#">KPI</a></li>
</ul> </div>


But the button are not appearing as in website. How to achieve this?
enter image description here



Chrome:



enter image description here





How to Get Eclipse, Maven and Google PlayN to work together?

I have tried three times now to get eclipse setup to run the playn-sample projects with no luck. I have tried the following starter guides:



http://davies-barnard.co.uk/2012/03/playn/



http://code.google.com/p/playn/wiki/GettingStarted



http://www.gamefromscratch.com/post/2011/10/13/Getting-started-with-PlayN.aspx



And have been able to get up to the import part of the guides when I start running into issues. I have cleaned out all JRE, JDK Eclipses installs, and currently have the following installed.



Java SE SDK 6u29



http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u29-oth-JPR



Android SDK r18



http://developer.android.com/sdk/index.html



Eclipse IDE for Java EE Developers



http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigor



m2e - Maven Integration for Eclipse v1.0.200.20111228-1245



(from all available update sites)



Android Plugin for Eclipse ver. 18.0.0.v201203301601-306762



https://dl-ssl.google.com/android/eclipse/



Google Plugin



http://dl.google.com/eclipse/plugin/3.7



Maven Integration for WTP ver. 0.15.2.20120306-2040



http://download.jboss.org/jbosstools/updates/m2eclipse-wtp



My experience starts deviating from the guides when I try to import the the playn-samples into the workspace. I keep getting the following error:




No marketplace entries found to handle android-maven-plugin:3.1.1:proguard in Eclipse. Please see Help for more information.




While I have been programming for years, my time has been in visual studio predominantly C#,ASP.NET, and in the past two years I have picked up jQuery/JavaScript. I programmed some in java back in college and saw the PlayN framework as a good reason to get back in. What am I missing from these guides to get up and running?





Activity Access Restriction Implementation in a Monodroid Application

I have a requirement where I need to restrict access to an activity of a Monodroid Application. Hence i tried a spike where the application IntentSayHello would have an access restricted Activity called SayHelloActivity. As the first step i defined the permission tag in the AndroidManifest.xml of the application as below:



...
...
</application>
<permission
android:name="intentsayhello.permission.SAYHELLO"
android:protectionLevel="signature" android:label="@string/permlbl_restricted"
android:description="@string/permdesc_restricted">
</permission>
</manifest>


Please note that i'm using protectionLevel = signature which means that any other application signed with the same certificate as IntentSayHello can only access the restricted activity.



Now i coded the SayHelloActivity as below:



    [Activity(Label = "SayHelloActivity", MainLauncher = true, Icon = "@drawable/icon", Permission = "intentsayhello.permission.SAYHELLO")]
[IntentFilter(new string[] { "companyXYZ.intent.sayhello.MAIN" },Categories = new string[]{Intent.CategoryDefault},
DataMimeType = "vnd.companyXYZ.say.hello/vnd.companyXYZ.activity")]
public class SayHelloActivity : Activity
{
.....
.....
}


After this i tested with a client application by invoking SayHelloActivity of IntentSayHello through an implicit intent and i got SecurityException as expected.



Permission Denial: starting Intent { act=companyXYZ.intent.sayhello.MAIN typ=vnd.companyXYZ.say.hello/vnd.companyXYZ.activity cmp=IntentSayHello.IntentSayHello/intentsayhello.SayHelloActivity }
from ProcessRecord{4094f850 9126:DiffKeyHello.DiffKeyHello/10097} (pid=9126, uid=10097) requires intentsayhello.permission.SAYHELLO



Now if i want my client Application to be given access to the SayHelloActivity of the restricted application, i'm supposed sign my client application with the same keystore (certificate) and also mention in the AndroidManifest.xml of the client application as below:



...
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="intentsayhello.permission.SAYHELLO" />
</manifest>


But when i did both of this, the client application still could not invoke the SayHelloActivity and same SecurityException is thrown.



I would like to know the directions/solution to this issue.
Thanks





Low Power Sensor Module

My next project requires me to have efficient wireless sensor modules. Basically, these modules should be able to read temperature, light, etc. sensor data and output it over its wireless transmitter/receiver. It can be any sensor and also it MUST be a transmitter and receiver.



My question is how to get it to very low power. I would like this setup to run for a year maybe 6 months but the current prototype I have with an Arduino chip and an XBee module sending data every minute cleans out a 9v battery in an hour. I have read a lot about this problem and wanted to know if XBee's are out of question. My worry is not the microcontroller, it is how to get efficient wireless communication while maintaining the budget on power consumption. Basically, what is the best low power wireless module out there?



Thanks!





Retrieve Json from service and pass to ApiController

I want to directly capture JSON from an external API in a service layer, return that to a MVC 4 ApiController, and then output the JSON through that ApiController. I'm basically writing a wrapper around another API service because some other actions have to happen at the same time (authentication, etc). The problem is that the JSON gets converted to a string and is passed around as a string in my C# code. This just adds escape characters to the JSON. Is there anyway I can just pass the JSON object around in my C# code? Details of my implementation are below.



In a service layer, I'm consuming an API that provides JSON via the method below.



return new WebClient().DownloadString(url);


Unfortunately this returns a string. As this API is already returning JSON to me this is problematic because lots of escape characters get added to the string.



The JSON should look something like this



[{"Citation":{"Attachments":[{"AttachedPersonIds":null,..."Type":"Record"}]


But instead it now looks like this



"[{\"Citation\":{\"Attachments\":[{\"AttachedPersonIds\":null,...\"Type\":\"Record\"}]"


After I get this string I return it through a couple of methods to an ApiController (which is setup to return JSON) like this.



public class HintsController : ApiController
{
public string Get(string treeId, string personId)
{
return _hintService.GetHints(treeId, personId);
}
}


I've tried to convert the string to a Literal string and tried serializing the string again. Doing this just adds more escape characters and doesn't solve the problem. I think the problem is with how I'm consuming the initial call because it's casting it from JSON to a string. But I don't know how to avoid this.



Thanks in advance for any ideas.





SGrid Column Header Grouping

I want to group column header in sGrid. for example click here.
But this example if for .js file. I want to do the same thing in Vb6 sGrid.





Merge Replication for Huge Tables

I have a problem. I have an audit table which is about 66 million rows, and the client wants to replicate it to another server, but this table has no cluster index, so the only way to do it is through merge replication, but it always times out, I gues this happends because the table is tat big.



I want to know if there is a way to do this without getting the timeout error?



Thanks.





module_layout version incompatibility

I try to insmod a linux kernel legacy module being ported by me.
The following errors appear:



> sudo insmod camac-mx.ko
insmod: error inserting 'camac-mx.ko': -1 Invalid module format
dmesg |tail -n 1
[1312783.938299] camac_mx: disagrees about version of symbol module_layout


How do I fix this?





Float a div to center

Hai guys,
I want to float a div to center is it possible. Text-align:center is not working in IE...





Using PHP to Access a User's Webcam

I'd like to allow users to record videos directly from their webcam.
I haven't done much work with PHP but am stuck with it for this project.
We currently have a system in place for video uploading and encoding, but nothing to actually access a user's webcam.
How would you recommend I proceed?





Live cloning of virtual machine

Please do anyone has a C/C++ example code for doing live cloning of VM running on xen? Also a useful tool that can achieve live cloning of VM in xen will be appreciated.



Thanks for your assistance.



Ifeanyi





Reload page when a certain width is passed

I want the page to reload only if the browser window goes above or below 768px.
This was my attempt which failed.



if ($(window.width() > "769") {
$(window).resize(function () {
if ($(window).width() < "769") {
location.reload();
}
});

}
elseif($(window.width() < "769") {

$(window).resize(function () {
if ($(window).width() > "769") {
location.reload();
}
});

}


Im sures theres a really simple way of doing this.





Convert arraylist object to byte[]

I have araylist object named list, here i want to convert my arraylist object to byte[], while doing the below coding its giving an error: "At least one element in the source array could not be cast down to the destination arraytype"
my coding:



 byte[] obj= new byte[list.Count];
list.CopyTo(obj);


here my array list objects returns report data from ssrs reports.what i want to do here to solve this issue.





upload file from client to server without openFile dialog

i am trying to create an aspx page where i can directly upload a file from the client to the server without user intervention. I would like to do something like when the user specifies the file path in the url, that particular file must be uploaded to the server.



example:
ht.tp://XXX.XXX.XXX.XXX/File_upload/File_Uploader.aspx?upload=C:/sample.csv&type=csv



The user can change the value after upload and what ever file he is specifying, it will be needed to be uploaded onto the server which is located at xxx.xxx.xxx.xxx



this is just a trial to check if the csv file is being created on the server or not, and it is not being created.



i just want to copy the file on the client side to the server side and it has to be only by the aspx page in the format specified above.
if there is any other good way then please guide me. Thanks.





Selecting multiple columns from a subquery

I've searched a lot, but still no chance on having a subquery to return multiple columns all at once. The following code works, but it sucks:



SELECT
(SELECT Column1 FROM dbo.fnGetItemPath(ib.Id)) AS Col1,
(SELECT Column2 FROM dbo.fnGetItemPath(ib.Id)) AS Col2,
(SELECT Column3 FROM dbo.fnGetItemPath(ib.Id)) AS Col3
FROM ItemBase ib


I actually have got no idea how to pass ib.Id to the function and get the entire Column1, Column2, Column3 columns without calling the fnGetItemPath function 3 times.



Thanks in advance





iFrame without source attribute but embeded html tag

I'm not that familiar with iframes and basically just want to find out if it's possible to exclude the 'src' attribute on an iframe tag and instead embed a html tag inside of it? For example:



<iframe id='myFrame'>
<html>
<head>...</head>
<body>
<h3>Hello World!</h3>
</body>
</html>
</iframe>


Also just a little side question, say this is indeed possible. And you're embeding this code in a JSP, would the java variables in the JSP also be visible to the html document in side the iframe's html tag?



Thanks guys!





FB Sharing with Android

I want to share custom text,image,decritpion all which FBConnect SDK does for ios in android.
Can anyone provide sample app for it.
hackbook is not understandable for me.
Thanx in advance.





Sequence format in Openerp

In openerp sequences we can insert current year with century as suffix or refix as following:



    /%(year)s 


I need to get the fiscal year as suffix in the sequence. Is there any possible way?



for eg: PO/0001/2012-2013





Faster alternative than Dictionary<Type, X>?

I'm creating a library which I'm performance testing. In it I generate a Dictionary<Type, X> once. The items are currently inserted in a random order. The dictionary remains unchanged during the application lifetime.



It's then frequently used to lookup items. The lookup is one of the larger bottlenecks in the library.



Yes, I'm micro-optimizing, but to learn. I'm wondering if there are a better way to get lookup performance?





how to delete header and footer except for watermarks

It is easy to delete whole header and footer by using delete command. But I want to delete everything from header/footer except watermarks(wordart) that falls in left half of the document. Kindly help. So far I am able to recognize the watermarks as below:



    For Each sec In worddoc.Sections
For Each hdr In sec.Headers
For Each sh In hdr.Shapes
If sh.Left > 200 Then
'Do something
End If
Next sh
Next hdr
Next sec


I request all you to kindly help me find solution for this. Thanks in advance.





splash screen gets error when going to the main activity

My splash screen gets error and it is going to force close the app. in Logcat is says Permission Denied. What should i do to fix this problem. Can anyone help me with that matter, Thanks a lot



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class SplashScreen extends Activity {
protected boolean _active = true;
protected int _splashTime = 4000;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);

// thread for displaying the SplashScreen
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
finish();
startActivity(new Intent("com.droidnova.android.splashscreen.BodyPartsGameActivity"));
stop();
}
}
};
splashTread.start();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
_active = false;
}
return true;
}
}




Post url from android to retrieve data

i have a url "http://184.82.158.234/~store/rest/system/connect.json" and posting this url with mozilla addon called poster returns data in form of json
what i want is to post this url from android to get that json data into androids view .



any help is highly appreciated
thanks





Remove an item from the list

I am creating a list where I am adding items from the list through a json data.
The problem i am facing is that I have a delete button, and on click of the button,
the selected item from the list has to be deleted from the store.



This is what i have tried



{
text: '',
id: 'deletenotesBtn',
iconCls:'trash',
iconMask: true,
ui:'action',
handler: function(){
var itemSelected = Ext.getCmp('noteslist').getSelection().remove();
// this.remove(this, true);
alert('item deleted');
}


Any suggestions on how i can achieve it?





Compiled PHP Framework

I DONT WANT TO COMPILE PHP TO NATIVE EXES OR ANYTHING LIKE THAT ONLY COMPILE/CACHE(both words dont reflect what i mean ;/) THE FRAMEWORK LOGIC ITSELF



Is there anything like a compiled PHP Framework ?



What i mean is take Kohana as an example. Its extensible, overrideable, fun, etc.



But it ends up loading 200 files to show one page !!
What i would think is best is if you have Controller_Admin extends Controller_Admin_Template extends Controller_Template extends Kohana_Controller_Template extends Controller extends Kohana_Controller . this isint needed... if we just copypasted method bodies to $parent->whatever() it would end up in one nice, smaller, faster file.



We allready do it for JS and CSS to minimise assets downloaded, why not the whole damn framework :D



Also i am looking for a compileable ORM. The Kohana ORM is very... slow... it uses magic methods, loads tables, generaly is fun to work with but a pain in the... circuitry of the server :P



if we could make ORM::factory('test')->compiled()->where('bla','=','1)->execute(); to compile into ORMC::factory('test','SELECT * FROM test WHERE bla=1')->execute(); in the production server it would be cool. This applies to a bunch of other stuff besides ORM but ORM would benefit greatly.



The overhead of dynamic frameworks doesnt seem to tip the scales by the ease of use in my opinion. With this we loose no ease and speed it up like hell of a lot ;)



So my question is : Does something like this exists? If not, is my logic flawed?



;)



Edit:



because of failed answers ill show more straight what i want to do



we have /application/ where there is the EXACT SAME code as without "compiling"



and /compiled_app/ where all (for example) queries that can be SIMPLIFIED are SIMPLIFIED (not object Query_Builder but SELECT blablablabla etc)



Also as much as having 50 files for one class adds a lot of umm... override vectors ? :D it is an UNNEEDED 100% GUARANTEED BOTTLENECK PERFORMANCE OVERHEAD. maybe its not much but its there allways. And it doesnt have to.





Map field to greater than field in Solr

I'm about to add a feature to my project that will allow users to place a Solr query like...



immigration law citations:50


...which would yield legal documents containing 'immigration' AND 'law' AND a citation count greater than 50.



Internally, I can parse out strings like citations:50 and convert them to citations:[50 TO *], but post-processing the query parser is best avoided if possible.



Seems like there ought to be a way in the schema to say, "When people search on this field, always look for the value the find anything greater."



Anything like that or ideas for how to do this elegantly? I hate query postprocessing in my app. Nasty stuff.