Skip to content

Instantly share code, notes, and snippets.

@aogilvie
aogilvie / string_encrypt_decrypt.md
Created August 19, 2013 08:52
Quick and sexy String encrypt / decrypt for Android

#Quick and sexy String encrypt / decrypt for Android

Sometimes you find yourself wanted to use SharedPrefs to hold something precious? Want to prevent those pesky rooted hackz0rs from looking in your SharedPreds? Here is a quick and sexy no-external-libs-required solution.

Notes;

  • I have declared everything static so you can create your own utility class and throw the following straight in.

  • 3rd party imports are not required. Use import android.util.Base64; for Base64, and import javax.crypto.*; for Cipher.

@aogilvie
aogilvie / trap.md
Last active November 2, 2021 04:53
JavaScript Code Trap Example #1
/**
 * Fetch users by projectId
 *
 * @param {String} projectId (required)
 * @param {Object} options (to further narrow query) e.g. [postcode, disabled]
 */
api.prototype.getUsers = function(projectId, options, cb) {
    let query = {
        projectId,
@aogilvie
aogilvie / keyboard_driver_hack.md
Created December 14, 2017 03:12
Japanese Apple Extended Keyboard Layout for Windows Hack
  • plug in your USB keyboard (if not using a laptop).
  • in Windows click start and type "keyboard" this should match the Keyboard window in the Control Panel.

screenshot1

  • Update the driver to Fujitsu 109 Japaese Keyboard.

screenshot2

@aogilvie
aogilvie / convert.md
Created August 31, 2017 04:08
Nix (CentOS) .md to .pdf with pandoc

Install pandoc

yum install -y texlive-latex texlive-latex-bin texlive
yum install -y pandoc

Given a file sample.md make sample.pdf

pandoc -o sample.pdf sample.md

@aogilvie
aogilvie / ProxyThingsForDocker.md
Last active November 14, 2016 05:13
Proxy Things For Docker

Notes on using proxy env vars with Docker or Dockerfile

Running the daemon behind a proxy:

sudo env https_proxy=http://proxy:8080 docker daemon

Building

sudo docker build --build-arg HTTP_PROXY=$http_proxy -t some/imagename .

@aogilvie
aogilvie / gist:5625088
Last active December 17, 2015 14:29
HttpUriRequest and HttpPut, sending a payload String with multilingual characters.

A Java String doesn't have an encoding but it can easily be forced into UTF-16 on conversions. ALWAYS specify UTF-8 when creating a new StringEntity from String!

Add payload to HttpPut
HttpPut hp = (HttpPut) this.request;
hp.setEntity(new StringEntity(yourStringPayload, "UTF-8"));
hp.setHeader("Content-Type", "application/json");
// ... then execute
@aogilvie
aogilvie / gist:102e6687780dd81c63d6
Created June 24, 2015 01:44
Atom IDE Proxy workaround

For 0.211.0 when behind a proxy.

# Windows temporary:
set ATOM_NODE_URL=http://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist

# Windows permanently:
setx ATOM_NODE_URL http://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist /M

# Linux
@aogilvie
aogilvie / prettyInfoScope.js
Last active December 7, 2015 03:01
Pretty console the scope of your console.info
(function() {
// Usage - attach scope to last argument for printing scope:
// console.info('whatever', this);
// console.info('whatever', { a: 'abc'}, ..., this);
if (window.console && console.info){
var old = console.info;
console.info = function() {
var len = arguments.length;
if (len -1 > 0 &&
Object.prototype.toString.call(arguments[len - 1]) === '[object Object]' &&
@aogilvie
aogilvie / gist:94eb38759624b3866bf3
Last active August 29, 2015 14:23
Linux: Cordova add android platform: TypeError: Request path contains unescaped char

Cordova: 5.1.1

Node.js: v0.12.0

Replace ~/Documents/node_modules/cordova/node_modules/cordova-lib/node_modules/npm/node_modules/request/index.js (or whatever the error output says)

with https://github.com/mikeal/tunnel-agent

@aogilvie
aogilvie / gist:cddeeb0b415d79a77b27
Last active August 29, 2015 14:07
Splitting a large commit after having created a PR

Scenario

Working on a feature branch, let's say "feature/local-notification". Once finished, one commits all the files and sends the PR to let's say "develop" on a remote repositiory used by your team.

When a reviewer comes to check the PR they announce they are unable to comment on diffs or view all the diffs on Github as Github's diff limit was reached.

You are asked to (kindly) split the commit...

Below I will outline the (what I think is the best and most flexible) method of doing this (there are perhaps other ways depending on your situation).