Django form field choices, adding an attribute

You’d have to subclass the field to take whatever means of specifying the title you’d like and the widget to display the new attribute. If you had something like this (note: entirely untested): from django import forms from django.utils.html import escape from django.utils.encoding import force_unicode class SelectWithTitles(forms.Select): def __init__(self, *args, **kwargs): super(SelectWithTitles, self).__init__(*args, **kwargs) # … Read more

How can I pass extra parameters to UDFs in Spark SQL?

Just use a little bit of currying: def convertDateFunc(resolution: DateResolutionType) = udf((x:String) => SparkDateTimeConverter.convertDate(x, resolution)) and use it as follows: case FieldDataType.Date => convertDateFunc(resolution(i))(allCols(i)) On a side note you should take a look at sql.functions.trunc and sql.functions.date_format. These should at least part of the job without using UDFs at all. Note: In Spark 2.2 or … Read more

LED flashlight on Galaxy Nexus controllable by what API?

What I found out is that some devices need a SurfaceView to turn on the LED. SurfaceView preview = (SurfaceView) findViewById(R.id.PREVIEW); SurfaceHolder mHolder = preview.getHolder(); mHolder.addCallback(this); Camera mCamera = Camera.open(); mCamera.setPreviewDisplay(mHolder); // Turn on LED Parameters params = mCamera.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_TORCH); mCamera.setParameters(params); mCamera.startPreview(); … // Turn off LED Parameters params = mCamera.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_OFF); mCamera.setParameters(params); mCamera.stopPreview(); mCamera.release(); … Read more

Tokenizing strings in C

Do it like this: char s[256]; strcpy(s, “one two three”); char* token = strtok(s, ” “); while (token) { printf(“token: %s\n”, token); token = strtok(NULL, ” “); } Note: strtok modifies the string its tokenising, so it cannot be a const char*.

Modifying .resx file in C#

There’s a whole namespace for resource management: System.Resources. Check out the ResourceManager class, as well as ResXResourceReader and ResXResourceWriter. http://msdn.microsoft.com/en-us/library/system.resources.aspx I managed to lay my hands on a very old debug method that I used to use at one point when I was testing some resource related stuff. This should do the trick for you. … Read more

How to save image in android gallery

the gallery don’t displaying (necessarily) files from external storage. this is a common mistake. the gallery displays images stored on the media store provider you can use this method to store image file on media store provider: public static void addImageToGallery(final String filePath, final Context context) { ContentValues values = new ContentValues(); values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis()); values.put(Images.Media.MIME_TYPE, … Read more

How to open a Windows named pipe from Java?

Use Named Pipes to Communicate Between Java and .Net Processes Relevant part in the link try { // Connect to the pipe RandomAccessFile pipe = new RandomAccessFile(“\\\\.\\pipe\\testpipe”, “rw”); String echoText = “Hello word\n”; // write to pipe pipe.write ( echoText.getBytes() ); // read response String echoResponse = pipe.readLine(); System.out.println(“Response: ” + echoResponse ); pipe.close(); } … Read more