Skip to content

Instantly share code, notes, and snippets.

View tjohns's full-sized avatar

Trevor Johns tjohns

View GitHub Profile
@tjohns
tjohns / sort.cpp
Created June 27, 2016 16:22
C++ sorting example
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int data[] = {2,4,3,5,1};
cout << "Input: " << data[0] << data[1] << data[2] << data[3] << data[4] << endl;
sort(begin(data), end(data));
cout << "Output: " << data[0] << data[1] << data[2] << data[3] << data[4] << endl;
@tjohns
tjohns / Android PBKDF2WithSHA1 Compatibility.java
Created November 13, 2013 03:16
Code snippet providing pre-4.4 compatibility for Android apps using SecretKeyFactory with PBKDF2WithSHA1.
import android.os.Build;
SecretKeyFactory factory;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Use compatibility key factory -- only uses lower 8-bits of passphrase chars
factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1And8bit");
Log.i(TAG, "Selected KITKAT key factory");
} else {
// Traditional key factory. Will use lower 8-bits of passphrase chars on older
// devices, and all available bits on KitKat (or newer) devices.
@tjohns
tjohns / 0_reuse_code.js
Created November 6, 2013 23:50
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
@tjohns
tjohns / gist:5107293
Last active December 14, 2015 15:19
Sample Google+ interactive post, retrieved via API
{
"kind": "plus#activity",
"etag": "\"TJ4YjXUi1XCM_G3FJ4uiPX8m6Fk/n9YjVnPuyW8gIfmE8SA3G0AkEAQ\"",
"title": "This is a test public interactive post to explore the Google+ API. Please ignore it. This will be deleted momentarily...",
"published": "2013-03-07T10:59:09.293Z",
"updated": "2013-03-07T10:59:09.293Z",
"id": "z12qcn5obvqts1ci104chv3iauvmz3r4lok0k",
"url": "https://plus.google.com/114249855229891870149/posts/ZKquCvZxAgT",
"actor": {
"id": "114249855229891870149",
@tjohns
tjohns / json ⊄ js: Hex Dump
Created December 28, 2012 02:13
json ⊄ js: Hex Dump
000018d8: 7468 6174 2074 6865 2066 6f6c 6c6f 7769 6e67 2073 7472 696e :that the following strin
000018f0: 6720 6973 2070 6572 6665 6374 6c79 2076 616c 6964 204a 534f :g is perfectly valid JSO
00001908: 4e3a 3c2f 703e 3c70 7265 206e 616d 653d 2239 3232 3622 3e7b :N:</p><pre name="9226">{
00001920: 2273 7472 223a 2022 6f77 6ee2 80a8 6564 227d 3c2f 7072 653e :"str": "own...ed"}</pre>
00001938: 3c70 206e 616d 653d 2266 6331 6422 3e54 7279 2063 6f70 7920 :<p name="fc1d">Try copy
00001950: 616e 6420 7061 7374 696e 6720 7468 6174 2074 6578 7420 696e :and pasting that text in
00001968: 746f 2074 6865 2063 6f6e 736f 6c65 2061 6e64 2061 7373 6967 :to the console and assig