Skip to content

Instantly share code, notes, and snippets.

@viperwarp
viperwarp / Questions
Created June 23, 2011 00:35
Kiwi Pycon Give-away
GitHub username: viperwarp
Day job: Mobile Developer
Favorite open source project: Bukkit
Open Source contributions (if any): None yet
Stranded on an island, what 3 items do you take: Pickaxe, Torch, Workbench
Tie-breaker, pick a number between 1 and 20,000: 16384
@viperwarp
viperwarp / ContentURIResolve.java
Created August 11, 2011 00:08
Resolves an Android "content://" URI to an actual image file in the gallery
// And to convert the image URI (content:// format) to the direct file system path of the image file
// From "http://www.androidsnippets.com/get-file-path-of-gallery-image"
public String getRealPathFromURI(Uri contentUri) {
// can post image
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
@viperwarp
viperwarp / icon.java
Created August 17, 2011 23:57
download and cache menu icons
//Download menu icons
if (menu != null && !menuImageURL.equals("")) {
File cacheDir = new File (ClassificationActivity.this.getCacheDir(), "/ic_menu/");
if (!cacheDir.exists()) cacheDir.mkdirs();
List<String> existingFiles = Arrays.asList(cacheDir.list());
for (int i = 0; i < menu.length(); i++) {
try {
String filename = menu.getJSONObject(i).getString("image");
@viperwarp
viperwarp / getJsonFromUri
Created October 19, 2011 23:29
Loads a JSON object from a file
public JSONObject getJsonFromUri(String url) throws JSONException, IOException {
URLConnection conn = null;
DataInputStream data = null;
String line;
StringBuffer buf = new StringBuffer();
conn = new URL(url).openConnection();
conn.connect();
data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
#!/bin/bash
# Originally written by Ralf Kistner <[email protected]>, but placed in the public domain
# Edited for log brevity by Affian <https://github.com/viperwarp>
set +e
bootanim=""
failcounter=0
echo "Waiting for Emulator"
@viperwarp
viperwarp / jsonHash.java
Last active October 21, 2015 21:24
Java JSON hashing
private long getJsonHashcode(@NonNull Object json) throws JSONException {
long result = 15l;
int multiplier = 27;
if (json instanceof JSONObject) {
JSONObject obj = (JSONObject) json;
for (Iterator<String> iterator = obj.keys(); iterator.hasNext(); ) {
String key = iterator.next();
Object value = obj.get(key);
result = multiplier * result + key.hashCode();
@viperwarp
viperwarp / ReactNativeJson.java
Created February 24, 2016 03:02
React-Native Module, ReadableMap/Array to Java JSON objects
private static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
WritableMap map = new WritableNativeMap();
Iterator<String> iterator = jsonObject.keys();
while (iterator.hasNext()) {
String key = iterator.next();
Object value = jsonObject.get(key);
if (value instanceof JSONObject) {
map.putMap(key, convertJsonToMap((JSONObject) value));
} else if (value instanceof JSONArray) {
@viperwarp
viperwarp / MyDispatchService.java
Created July 29, 2016 03:31
An Android Service that catches an implicit service intent and forwards to all services implementing that intent filter.
import android.app.IntentService;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.Log;
import java.util.List;
public class MyDispatchService extends IntentService {
import android.annotation.SuppressLint
import android.support.design.widget.NavigationView
import android.support.v4.widget.DrawerLayout
import android.view.MenuItem
import androidx.navigation.NavController
import androidx.navigation.NavOptions
/**
* @author https://github.com/viperwarp
*