Skip to content

Instantly share code, notes, and snippets.

View jlongster's full-sized avatar
💭
Workin on my app

James Long jlongster

💭
Workin on my app
View GitHub Profile
import React from 'react';
import lively from 'lively';
// Global registry and resize handler
let _registeredInstances = [];
function register(inst) {
if (_registeredInstances.length === 0) {
window.addEventListener('resize', onResize);
}
@jlongster
jlongster / gist:1245398
Created September 27, 2011 15:34
PHP MADNESS
$url_parts = explode('/', trim($_SERVER['REDIRECT_URL'], '/'));
if ($url_parts[0] != $lang) {
// Bug 619404 Quickly redirect homepage
if ($_SERVER['REQUEST_URI'] == '/') {
$_SERVER['REQUEST_URI'] = '/firefox/';
}
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
// This matches both / and /firefox because of the above code
@jlongster
jlongster / csp.js
Last active January 9, 2021 16:09
very basic CSP in JavaScript
var fs = require('fs');
// machine
function go_(machine, step) {
while(!step.done) {
var arr = step.value();
var state = arr[0];
var value = arr[1];
var dom = Bloop.dom;
var Box = Bloop.createClass({
getInitialState: function() {
return { number: 0 };
},
updateNumber: function() {
this.state.number++;
},
// Uses Buffer from https://github.com/feross/buffer
function toArrayBuffer(buffer) {
return buffer.buffer.slice(
buffer.byteOffset,
buffer.byteOffset + buffer.byteLength
);
}
async function run() {
const async_hooks = require('async_hooks');
let store = new Map();
let promiseStorageHook = async_hooks.createHook({
init(id, type, triggerId, resource) {
if (store.get(triggerId)) {
if (type === 'PROMISE') {
store.set(id, store.get(triggerId));
}
// Example code, see below for run/yield implementation. Note how we
// can even do yields across the stack, so this implements something
// more like coroutines than generators.
function foo() {
var x = Yield();
return x + 1;
}
var process = Run(function() {
@jlongster
jlongster / gist:1840230
Created February 16, 2012 00:03
tracing Outlet code
(trace-source (let ((i (+ 4 5)))
(+ i (* 2 (/ 3 4)))))
;; Output
(let ((i (+ 4 5)))
(+ i (* 2 (/ 3 4))))
-- (+ 4 5)
>> RESULT: 9
import React from 'react';
import { View, Text, ScrollView, TouchableOpacity } from 'react-native';
let NamespaceContext = React.createContext(undefined);
export default class ExamplePage extends React.Component {
constructor() {
super();
this.state = { currentMonth: 1 };
}

Head Over Heels for Snapshot Testing

Tests are interesting, because you're trying to test code. But to write tests, you have to write code. Who tests the tests? For tests to be worth it you need to be sure that for each line of code you add, the value being added is more than the liability.

Value > Liability

Because belive me, tests are a liability. First, they are code that