Skip to content

Instantly share code, notes, and snippets.

View 3mcd's full-sized avatar
🦌

Eric McDaniel 3mcd

🦌
View GitHub Profile
@3mcd
3mcd / phonegap-ios-7-status-bar-fix.m
Last active January 2, 2017 14:27
Place this snippet in the view controller (MainViewController, ChildBrowserViewController, etc) to push the view down 20px to account for the transparent iOS 7 status bar.
@implementation MainViewController
- (void)viewWillAppear:(BOOL)animated
{
// Lower screen 20px on iOS 7
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect viewBounds = [self.view bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
@3mcd
3mcd / breach-launcher.bash
Last active August 29, 2015 14:03
Breach browser linux launcher script
#! /bin/bash
BREACH_PATH=/opt/breach/breach # Path to your breach installation
SANDBOX_PATH=/opt/google/chrome/chrome-sandbox # Path to your chrome sandbox installation
export CHROME_DEVEL_SANDBOX=$SANDBOX_PATH
screen -d -m $BREACH_PATH
@3mcd
3mcd / mysql_drop_all_tables_from_database.bash
Last active August 29, 2015 14:08
Drop all tables from MySQL db
mysql --user=YOUR_USERNAME --password=YOUR_PASSWORD -BNe "show tables" YOUR_DBSCHEMA_NAME | tr '\n' ',' | sed -e 's/,$//' | awk '{print "SET FOREIGN_KEY_CHECKS = 0;DROP TABLE IF EXISTS " $1 ";SET FOREIGN_KEY_CHECKS = 1;"}' | mysql --user=YOUR_USERNAME --password=YOUR_PASSWORD YOUR_DBSCHEMA_NAMEt
@3mcd
3mcd / parse-query-params.js
Last active December 16, 2015 03:48
Parse URL Query Parameters
function getQueryParameters(str) {
return (str || document.location.search)
.replace(/(^\?)/, '')
.split('&')
.reduce(function (a, x, i) {
var n = x.split('='), y = n[0], z = n[1];
try { z = JSON.parse(z); } catch(e) { }
a[y] = a[y] ? typeof a[y] == 'object' ? (a[y].push(z) && a[y]) : [a[y], z] : z;
return a;
}, {});
{% exercise %}

Using the mean() function above, find the mean of `x`, `y`, and `z`, and assign it to `result`.

{% initial %}
var x = 5, y = 10, z = 20;
var result = ;

{% solution %}
@3mcd
3mcd / tonic1.js
Last active December 17, 2015 21:56
var assert; // TODO: write some assert lib/function
function success() {
// TODO: make some call to store student answer
}
function failure() {
// TODO: make some call to store student answer, update notebook with hints, etc
}
@3mcd
3mcd / tonic2.js
Last active January 6, 2016 14:16
import { success, failure } from './assessment';
var results = [];
Tonic.createNotebook({
element: document.getElementById('embed'),
source: ``,
// Add script tag to src="https://raw.githubusercontent.com/bettiolo/oauth-signature-js/master/dist/oauth-signature.min.js"
// to get oauthSignature function on window (global)
function randomString(length, chars) {
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}
function jsonp(url, callback) {
const _ensureNew = (ctor) => {
const fn = (...args) => !(this instanceof ctor) ? new ctor(...args) : ctor(...args);
fn.prototype = ctor.prototype;
return fn;
}
const ensureNew = (ctor) => {
const fn = _ensureNew(ctor);
fn.extend = Backbone.Model.extend;
return fn;
@3mcd
3mcd / guard.js
Last active December 31, 2016 00:20
const $rest = Symbol('rest');
const $normal = Symbol('normal');
const $optional = Symbol('optional');
const $pattern = Symbol('pattern');
const eq = a => b => a === b;
const toString = val => Object.prototype.toString.call(val).split(' ')[1].slice(0, -1);
const isString = a => typeof a === 'string';
const isArray = a => Array.isArray(a);