Create and Share a File from Internal Storage

It is possible to expose a file stored in your apps private directory via a ContentProvider. Here is some example code I made showing how to create a content provider that can do this. Manifest <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.providertest” android:versionCode=”1″ android:versionName=”1.0″> <uses-sdk android:minSdkVersion=”11″ android:targetSdkVersion=”15″ /> <application android:label=”@string/app_name” android:icon=”@drawable/ic_launcher” android:theme=”@style/AppTheme”> <activity android:name=”.MainActivity” android:label=”@string/app_name”> <intent-filter> <action android:name=”android.intent.action.MAIN” /> … Read more

How to use YamlPropertiesFactoryBean to load YAML files using Spring Framework 4.1?

With XML config I’ve been using this construct: <context:annotation-config/> <bean id=”yamlProperties” class=”org.springframework.beans.factory.config.YamlPropertiesFactoryBean”> <property name=”resources” value=”classpath:test.yml”/> </bean> <context:property-placeholder properties-ref=”yamlProperties”/> Of course you have to have the snakeyaml dependency on your runtime classpath. I prefer XML config over the java config, but I recon it shouldn’t be hard to convert it. edit: java config for completeness sake … Read more

Efficient 128-bit addition using carry flag

Actually gcc will use the carry automatically if you write your code carefully… Current GCC can optimize hiWord += (loWord < loAdd); into add/adc (x86’s add-with-carry). This optimization was introduced in GCC5.3. With separate uint64_t chunks in 64-bit mode: https://godbolt.org/z/S2kGRz. And the same thing in 32-bit mode with uint32_t chunks: https://godbolt.org/z/9FC9vc (editor’s note: Of course … Read more

How to get page content using cURL?

this is how: /** * Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an * array containing the HTTP server response header fields and content. */ function get_web_page( $url ) { $user_agent=”Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0″; $options = array( CURLOPT_CUSTOMREQUEST =>”GET”, //set request type post or get CURLOPT_POST … Read more

How to get PHP $_GET array?

The usual way to do this in PHP is to put id[] in your URL instead of just id: http://link/foo.php?id[]=1&id[]=2&id[]=3 Then $_GET[‘id’] will be an array of those values. It’s not especially pretty, but it works out of the box.

How can I list all classes loaded in a specific class loader

Try this. It’s a hackerish solution but it will do. The field classes in any classloader (under Sun’s impl since 1.0) holds hard reference to the classes defined by the loader so they won’t be GC’d. You can take a benefit from via reflection. Field f = ClassLoader.class.getDeclaredField(“classes”); f.setAccessible(true); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Vector<Class> classes … Read more