Skip to content

Instantly share code, notes, and snippets.

@awendland
awendland / WebStorage.ts
Last active December 14, 2015 02:31 — forked from heyimalex/WebStorage.js
localStorage sync with redux and TypeScript
export default class WebStorage {
private key: string;
private storageArea: Storage;
constructor(key: string, storageArea = window.localStorage) {
this.key = key;
this.storageArea = storageArea;
}
@awendland
awendland / GoogleApiInstance.java
Created August 10, 2015 01:23
A management class for maintaining a single instance of a Google API Client for an application. This class will provide methods for registering actions upon status events.
import android.content.Context;
import android.os.Bundle;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.common.api.GoogleApiClient;
import java.util.ArrayList;
import java.util.List;
/**
@awendland
awendland / Optional.java
Created July 20, 2015 21:13
A self contained implementation of Java 8's Optionals that can be placed in any project in order to gain the code clarity of the Optional class. This was extracted and modified from the OpenJDK 8
package com.alexwendland.example.utils;
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
@awendland
awendland / huffman.java
Last active August 29, 2015 14:24
A huffman code table generator from a given input string
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Alex Wendland © 2015
*/
@awendland
awendland / json-database-metadata.java
Created July 10, 2015 01:31
Converts a java.sql.DatabaseMetaData object to a JSON friendly Map<String, Object>. This is intended for debugging running Java Web APIs
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Map<String, Object> getMapOfDatabaseMetaData(DatabaseMetaData dbMeta) {

Android Cheat Sheet

Styles

Font family

android:fontFamily="sans-serif"                 // roboto regular
android:fontFamily="sans-serif-light"           // roboto light
android:fontFamily="sans-serif-condensed"       // roboto condensed
@awendland
awendland / dl_in_pieces.py
Created June 4, 2015 21:02
This simple python script downloads the retina wallpapers from the gorgeous http://species-in-pieces.com web experience
#! /usr/bin/env python
#
# This should be run from whichever director is desired for the wallpapers to be downloaded to
#
# Also, take a look at http://species-in-pieces.com/, it's a gorgeous website!
#
# Thank you to Bryan James for creating Species in Pieces
#
@awendland
awendland / pretty-date.js
Created June 4, 2015 00:16
JS function that takes an ISO time and returns a string representing how long ago the date represents.
/*
* JavaScript Pretty Date
* Copyright (c) 2011 John Resig (ejohn.org)
* Licensed under the MIT and GPL licenses.
*/
// Takes an ISO time and returns a string representing how
// long ago the date represents.
function prettyDate (time) {
var date = time instanceof Date ? time : new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
diff = (((new Date()).getTime() - date.getTime()) / 1000),
@awendland
awendland / obscure-example.html
Last active August 29, 2015 14:22
Reverse the textContents of an element in order to hide an email by pasting it in reverse in the source, but displaying it properly after the "unObscureElements" JS function runs.
<span class="obscure">moc.elpmaxe@eman</span> will become <span ...>[email protected]</span> after the JS runs
@awendland
awendland / 0_reuse_code.js
Last active August 29, 2015 14:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console