Skip to content

Instantly share code, notes, and snippets.

View 0x1mason's full-sized avatar

Eric Millin 0x1mason

  • IBM
  • Durm, Cackalack del Norte
View GitHub Profile
@0x1mason
0x1mason / string_template.js
Last active August 29, 2015 13:56
C# and Python inspired string templates for JavaScript
// Eric Millin (c) 2014
// MIT X11 license (http://opensource.org/licenses/MIT)
//
// C# and Python inspired string templating. Target tokens must be numbered with the index of the
// replacement string and surrounded by curly brackets; e.g:
//
// "{0} {1} {0}".format("foo", "bar"); // "foo bar foo"
//
@0x1mason
0x1mason / _readme
Last active August 29, 2015 14:06
Pseudo code example of lib/devices refactoring using a polymorphic approach. I also tried to use class names that might work with changes bootstrap suggested.
The files will make the most sense if you read them in this order:
device.js
android-base-device.js
android-uiautomator.js
others.js
I hate how gist doesn't give you the ability to keep the files in the original order.
@0x1mason
0x1mason / clear-spec.js
Created September 17, 2014 13:08
hide keyboard
it('should hide keyboard using bad key', function (done) {
driver
.elementByClassName('UIATextField').sendKeys("1")
.elementByClassName('UIASwitch').isDisplayed()
.should.become(false)
.hideKeyboard("f")
.elementByClassName('UIASwitch').isDisplayed()
.should.become(true)
.nodeify(done);
// in helpers.js
Object.prototype.forOf = function(iterateFunc) {
var keys = Object.keys(this),
continueLoop = true;
var breakLoop = () => continueLoop = false;
for(var counter = 0; counter < keys.length && continueLoop; counter++) {
iterateFunc(this, keys[counter], breakLoop);
}
};
@0x1mason
0x1mason / socket.js
Last active August 29, 2015 14:11
hackathon socket magic
var net = require("net");
var exec = require('child_process').exec;
var ADB = require('appium-adb');
//var adb = new ADB();
var template = '{"action":"Prepare", "cmd":"foo"}';
// var args = process.argv.slice(2).join(' ');
// adb.getConnectedDevices(function(err, devices) {
@0x1mason
0x1mason / gist:5c9dd03c22fd765fec5e
Last active April 21, 2018 22:42
Chromium Build Setup
apt-get update
apt-get install -qy git clang
mkdir ~/chromium
cd ~/chromium
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
echo "export DEPOT_TOOLS=\"\$HOME/chromium/depot_tools\"" >> ~/.bashrc
echo "export PATH=\"\$PATH:$DEPOT_TOOLS\"" >> ~/.bashrc
/// <summary>
/// Generator that allows lazy access to paginated resources.
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <param name="overrideUrl"></param>
/// <param name="pageLen"></param>
/// <returns></returns>
protected IEnumerable<List<TValue>> IteratePages<TValue> (string overrideUrl, int pageLen = DEFAULT_PAGE_LEN) {
Debug.Assert(!String.IsNullOrEmpty(overrideUrl));
Debug.Assert(!overrideUrl.Contains("?"));
@0x1mason
0x1mason / Instructions.md
Created January 16, 2016 22:55 — forked from pgilad/Instructions.md
Git commit-msg hook to validate for jira issue or the word merge

Instructions

  • copy the file commit-msg to .git/hooks/commit-msg
  • make sure your delete the sample file .git/hooks/commit-msg.sample
  • Make commit msg executable. chmod +x .git/hooks/commit-msg
  • Edit commit-msg to better fit your development branch, commit regex and error message
  • Profit $$

Shell example

@0x1mason
0x1mason / pre-push.sh
Created January 18, 2016 15:18 — forked from pixelhandler/pre-push.sh
Git pre-push hook to prevent force pushing master branch
#!/bin/sh
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...
# 1. Copy the file into your repo at `.git/hooks/pre-push`
# 2. Set executable permissions, run `chmod +x .git/hooks/pre-push`
function getBranch {
git symbolic-ref --short HEAD 2> /dev/null
if [ $? == 0 ] && [ `git rev-parse --is-inside-work-tree`==true ]; then
echo "(`git symbolic-ref --short HEAD`)"
fi
}
function setPrompt {
GIT_EXEC_PATH=/c/tools/cmder/vendor/git-for-windows/mingw64/
COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"