Skip to content

Instantly share code, notes, and snippets.

@dasibre
dasibre / modulePattern.js
Created March 5, 2016 21:08
javascript module pattern
var testModule = (function() {
var counter = 0;
return {
incrementCounter: function () {
return counter++;
},
resetCounter: function () {
console.log("counter value prior to reset: " + counter);
counter = 0;
}
@dasibre
dasibre / objectCreation.js
Created March 5, 2016 21:12
javascript object creation patterns
Object.defineProperty(newObject,"name", {
value: "Kwame",
writable: false,
enumerable: true,
configurable: true
});
var defineProp = function (obj, key, value) {
var config = {
value: value,
@dasibre
dasibre / pedantically_commented_playbook.yml
Created March 23, 2016 23:41 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
@dasibre
dasibre / name-score.clj
Last active May 28, 2016 12:56
name-score-problem
(defn accum1
[h pair-arry]
(if (contains? h (get pair-arry 1))
(merge-with conj h (hash-map (get pair-arry 1) (get pair-arry 0)))
(merge-with conj h (hash-map (get pair-arry 1) [(get pair-arry 0)]))))
;; short version of accum
(defn accum2
[h pair-arry]
(merge-with conj h (hash-map (keyword (get pair-arry 1)) (if (contains? h (keyword (get pair-arry 1))) (get pair-arry 0) [(get pair-arry 0)]))))
@dasibre
dasibre / _spec.rb
Created June 11, 2016 15:01
rspec idioms for cleaner tests
describe Thing do
def given_thing_with(options)
yield Thing.new do |thing|
thing.set_status(options[:status])
end
end
it "should do something when ok" do
given_thing_with(:status => 'ok') do |thing|
thing.do_fancy_stuff(1, true, :move => 'left', :obstacles => nil)
def construct_concept(concept)
h = {}
c = Hash[*concept.to_a.first]
c['paths'] = [[Hash[*concept.to_a.first]]]
h[concept['id']] = c
h
end
def parent_child_concepts(concepts)
pc = {}
@dasibre
dasibre / cljscript.cljs
Created August 5, 2016 19:59
learning cljs
[re-frame.core :as re-frame]
[ajax.core :as ajax]
[day8.re-frame.http-fx :as reg-fx]
(defn newpage [ratom]
(println "new page")
[:div
[:h2 (:api-result ratom)]])
(defn page [ratom]
(let [on-click (fn [] (re-frame/dispatch [:handler-with-http app-state]) (reagent/render [newpage app-state]
@dasibre
dasibre / sort.js
Created October 11, 2016 16:16
data to be sorted and expected output
var data = [
{ lastName: 'Bishop',
firstName: 'Timothy',
gender: 'Male',
favoriteColor: 'Yellow',
dateOfBirth: '4/23/1967' },
{ lastName: 'Bonk',
firstName: 'Radek',
middleInitial: 'S',
gender: 'Male',
@dasibre
dasibre / child-test.js
Created December 9, 2016 14:26 — forked from cowboy/child-test.js
Node.js: I can't seem to capture a child process's stdout and stderr in Windows.
var parent = function() {
var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [process.argv[1], 123]);
var stdout = '';
var stderr = '';
child.stdout.on('data', function(buf) {
console.log('[STR] stdout "%s"', String(buf));
stdout += buf;
});
child.stderr.on('data', function(buf) {
@dasibre
dasibre / stateful.js
Created May 29, 2017 13:16 — forked from foca/stateful.js
Stateful is a simple implementation of the State Pattern for JavaScript.
// Stateful is a simple implementation of the state pattern for javascript.
//
// Read more on this design pattern here:
// -> http://sourcemaking.com/design_patterns/state
//
// Initialize Stateful by passing it an object, the name of the initial state
// (defaults to "default"), and an optional hash of interfaces that will be
// applied for each state. If these interfaces are not passed, they default to
// the object's constructor's States property. So, for example:
//