Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Daniel Stocks danielstocks

🏠
Working from home
View GitHub Profile
@danielstocks
danielstocks / app.json
Created Mar 2, 2018
Expo Configuration FIle
View app.json
{
"expo": {
"name": "Carvanro",
"description": "A simple, quick, cheap and fun way to commute together",
"slug": "Carvanro",
"privacy": "public",
"sdkVersion": "24.0.0",
"version": "1.1.0",
"platforms": ["android"],
"orientation": "portrait",
View hmmm.jsx
const testPageJSON = {
"children": [
{
"el": "div",
"props": {
"style": {
"background": "green"
}
},
"children": [
View arrayToOptionsObject.jsx
const HOURS = [
'05', '06', '07', '08', '09', '10', '11', '12',
'13', '14', '15', '16', '17', '18', '19', '20',
'21', '22', '23', '00', '01', '02', '03', '04',
]
/*
* Converts ['05'] to {'05': '05'}
*/
const arrayToOptionsObject = (array => (
View gist:e049d35cf09f3f61b4cc85035a41ad48
// Paste and run in console!
alert(["0707", 92042, 697, 2746, 8646, 1792, 1].reduce(function(a, b) {
return a + b.toString()
}, "48617").split("").map(function(s, i, list) {
var x;
if (i % 2) x = list[i + 1] + (list[i + 2] ||  "");
if (i == 0) x = list[0] + list[1];
return x;
}).filter(function(item) {
return typeof item === 'string';
@danielstocks
danielstocks / gist:5da83982d3b4c7b503a0
Created Oct 17, 2014
Pretty print a JavaScript Tree Data Structure
View gist:5da83982d3b4c7b503a0
// Example implementation: http://jsfiddle.net/2f7w2fpn/
var indent = 1;
function walk(tree) {
tree.forEach(function(node) {
console.log('--' + Array(indent).join('--'), node.key);
if(node.children) {
indent ++;
walk(node.children);
}
@danielstocks
danielstocks / gist:2490995
Created Apr 25, 2012
Testing multiple HTTP status codes
View gist:2490995
/*
* Disregard the fact that I'm using Array.forEach here
*/
TestCase("ReadyStateHandlerTest", {
"test should call failure handler for 404, 400, 500": function() {
var _this = this;
[400, 404, 500].forEach(function(status) {
var request = forceStatusAndReadyState(_this.xhr, status, 4)
assert(request.failure);
View compile.js
// dust.js template pre-compilation
var template = dust.compile("Hello {name}!");
// compiles to this string:
//
// '(function() {
// dust.register("demo", body_0);
//
// function body_0(chk, ctx) {
View gist:827322
<!doctype html>
<html>
<head>
<style>
.theme {
width:400px;
margin:0 2px;
padding: 10px;
View Remove bloat.
find -name "*.py" | xargs perl -p -i -e 's/\s+\n/\n/g'
View gist:582777
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>IE input value</title>
</head>
<body>
<form action="">
<input id="test" type="text" name="username">
</form>