Skip to content

Instantly share code, notes, and snippets.

View daveshah's full-sized avatar
💭
💻

Dave Shah daveshah

💭
💻
View GitHub Profile
@daveshah
daveshah / setjdk.sh
Last active August 29, 2015 14:24
toggle between multiple JDK versions
#!/bin/bash
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
@daveshah
daveshah / YourCustomAdapter.java
Created May 4, 2015 17:27
Quick example of ListFragment Usage
public class YourCustomAdapter extends ArrayAdapter<Integer> {
private static final int LAYOUT_ID = R.layout.adapter_custom_list_item;
public YourCustomAdapter(Context context, List<Integer> imageIds) {
super(context, LAYOUT_ID, imageIds);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
@daveshah
daveshah / gist:bd97f0c1a2bd9b65dfc4
Created March 27, 2015 19:55
Modifying the index of an array in a property of a mongo doc
> db.spike.insert({sensorName:"name",sensorData:[{prop:"foo"},{prop:"foo1"}]})
WriteResult({ "nInserted" : 1 })
> db.spike.find()
{ "_id" : ObjectId("5515b49ee2666b1d26be97ce"), "sensorName" : "name", "sensorData" : [ { "prop" : "foo" }, { "prop" : "foo1" } ] }
> db.spike.update({sensorName:{$eq:"name"}},{$set:{"sensorData.0":{"prop":"works"}}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.spike.find()
{ "_id" : ObjectId("5515b49ee2666b1d26be97ce"), "sensorName" : "name", "sensorData" : [ { "prop" : "works" }, { "prop" : "foo1" } ] }
@daveshah
daveshah / PrettyPrintJson
Last active August 29, 2015 14:17
Pretty Print JSON
echo '{"foo": "lorem", "bar": "ipsum"}' | python -m json.tool
/**
* A collection of authentication and account connection utilities. With strong inspiration from the Google IO session
* app.
* @author Dandré Allison
*/
public class AccountUtils {
/**
* Interface for interacting with the result of {@link AccountUtils#getUserProfile}.
*/
@daveshah
daveshah / GetsMyInfo.java
Created December 22, 2014 03:40
Is There A Better Way?
package com.burningriverbitworks.myapplicatiozen;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Application;
import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.telephony.TelephonyManager;
import android.test.ApplicationTestCase;
@daveshah
daveshah / fizzbuzz.sql
Created May 13, 2014 17:06
FizzBuzz in SQL... just because
with numbers (number) as (
select number = 1
union all
select number = number + 1
from numbers
where number < 102
) select
number,
case
@daveshah
daveshah / snip_lister.rb
Last active January 3, 2016 03:18
Find all the snips!
def all_css_files_in(files_file)
css_files = []
File.readlines(files_file).each { |line|
unless line.start_with?("/Style%20Library","styles","http","/_control")
css_files << line.gsub("/_layouts/ui/css/","").gsub("?ver=20131220130545","").gsub("?ver=20131220130545","").gsub("?ver=20131220130545","")
end
}
css_files
end
@daveshah
daveshah / crawler.rb
Last active January 1, 2016 13:09
Crawling the clinic site for all our css yo'
require 'anemone'
require 'nokogiri'
require 'set'
@url = "http://my.clevelandclinic.org/default.aspx"
@moss_garbage = "layouts/1033/styles"
@css_link_set = Set.new
@flash_link_set = Set.new
*.csproj -text merge=union
*.sln -text merge=union