Skip to content

Instantly share code, notes, and snippets.

View danielearwicker's full-sized avatar
💭
Learning, yearning, occasionally gurning

Daniel Earwicker danielearwicker

💭
Learning, yearning, occasionally gurning
View GitHub Profile
@danielearwicker
danielearwicker / person.js
Created February 16, 2013 12:20
Object instances without using this/new/prototype
var person = function(firstName, lastName) {
return {
getFullName: function() {
return firstName + ' ' + lastName;
},
setFirstName: function(newName) {
firstName = newName;
},
setLastName: function(newName) {
@danielearwicker
danielearwicker / node-recursion-sync
Created July 22, 2013 08:44
A pure library approach to async/await in standard JavaScript - #1
var fs = require('fs');
var path = require('path');
var recurseDir = function(dir) {
fs.readdirSync(dir).forEach(function(child) {
if (child[0] != '.') {
var childPath = path.join(dir, child);
if (fs.statSync(childPath).isDirectory()) {
recurseDir(childPath);
} else {
@danielearwicker
danielearwicker / node-recursion-async
Created July 22, 2013 08:46
A pure library approach to async/await in standard JavaScript #2
var fs = require('fs');
var path = require('path');
var Q = require('q');
var interrupt = require('./interrupt.js');
var readdir = interrupt.bind(Q.nfbind(fs.readdir));
var stat = interrupt.bind(Q.nfbind(fs.stat));
var consoleLog = interrupt.bind(console.log);
@danielearwicker
danielearwicker / app.ts
Last active August 29, 2015 14:16
TypeScript module merging
Test.foo(v => v > 5);
@danielearwicker
danielearwicker / listenTo.js
Created March 17, 2015 12:49
Simple demo of pre-logging aspect
function listenTo(target, notify) {
var proxy = {};
Object.keys(target).forEach(function(methodName) {
var targetMethod = target[methodName].bind(target);
proxy[methodName] = function() {
var args = Array.prototype.slice.call(arguments);
@danielearwicker
danielearwicker / MediaWikiBackup.cs
Created February 19, 2016 13:30
Simple minimal backup of mediawiki
using System;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
namespace WikiBackup
{
class Program
interface Person {
readonly name?: string;
readonly age?: number;
}
const x = record<Person>({ name: "Bart" }).set({ age: 10 });
const y = x.set({ age: 11 });
@danielearwicker
danielearwicker / example.ts
Last active February 19, 2017 09:31
Remox (Redux in MobX)
import { autorun } from "mobx";
import { createStore, Action, Reducer } from "./remox"
interface Person { firstName: string; lastName: string; }
interface SetFirstName { type: "SET_FIRST_NAME", newFirstName: string; }
interface SetLastName { type: "SET_LAST_NAME", newLastName: string; }
function personReducer(state:Person, action: SetFirstName | SetLastName) {
@danielearwicker
danielearwicker / CudoEvent.cs
Created January 21, 2017 21:52
Cudo (Create, Update, Delete, Observe) - subscribers get Create events to recreate current contents, followed by subsequent updates
namespace Cudo
{
public class CudoEvent<TRecord>
{
public CudoEvent(CudoEventType type, TRecord record)
{
Type = type;
Record = record;
}
@danielearwicker
danielearwicker / twoWay.js
Created July 8, 2017 08:22
Very minimal two-way binding example
import React from 'react';
function twoWay(Comp) {
return props => {
const { value, children, ...others } = props;
return (
<Comp {...others}