Skip to content

Instantly share code, notes, and snippets.

View knitfaced's full-sized avatar

Polly McEldowney knitfaced

View GitHub Profile
@knitfaced
knitfaced / RavelryClientSignin.java
Created November 1, 2010 21:46
snippet to connect to the Ravelry API
private String createShopSearchQuery() throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
String jsonAction = "http://api.ravelry.com/shops/search.json?";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
Calendar now = Calendar.getInstance();
String timestamp = df.format(now.getTime());
String searchTerm = "yarn";
int shop_type_id = 1;
String query = jsonAction;
query += "access_key=" + urlEncode(ACCESS_KEY);
private String encryptCredentials(String plaintext) throws Exception {
String algorithm = "AES/CBC/PKCS5Padding";
SecretKeySpec skeySpec = new SecretKeySpec(SECRET_KEY.getBytes(), algorithm);
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(plaintext.getBytes());
return new String(encrypted);
@knitfaced
knitfaced / gist:1362533
Created November 13, 2011 19:21
upgrading sqlite database in android
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion);
if (newVersion > oldVersion) { // Upgrade
switch (oldVersion) {
case 1:
// Upgrade from version 1 to 2.
try {
Log.i(TAG, "upgrade 1->2: adding new column");
db.execSQL("ALTER TABLE " + DATABASE_TABLE + " ADD COLUMN " + NEW_COLUMN + " INTEGER;");