Skip to content

Instantly share code, notes, and snippets.

View ninegrid's full-sized avatar

Daniel Jackson ninegrid

  • ⋮ ⋮ ⋮
  • 30.2669° N, 97.7428° W
View GitHub Profile
@ninegrid
ninegrid / steps.rb
Created October 25, 2012 10:27
Cucumber + Capybara-webkit
When /^I add a link "(.*?)" replacing "(.*?)" content with "(.*?)"$/ do |link_name, element_selector, new_content|
page.execute_script("
var link_element = document.createElement('a');
link_element.setAttribute('onclick','jQuery(\\'#{element_selector}\\')[0].innerHTML = \\'#{new_content}\\'');
link_element.setAttribute('href', '#');
link_element.innerHTML = '#{link_name}';
jQuery('body')[0].appendChild(lLinkElement);
")
end
@ninegrid
ninegrid / masonic_template.hbs
Created February 3, 2014 22:31
an ember view for masonry
{{#view "masonic"}}
<section class="bricks">
{{! your template here}}
</section>
{{/view}}
@ninegrid
ninegrid / problem.js
Created March 14, 2014 22:57
Creating a child object with a hasMany relation to the parent record is strait forward, however how do I create a reciprocal relationship on the child?
// in my ArrayController
actions: {
create: function() {
var person = this.get('controllers.person.content');
var name = this.get('newName');
if (name && !name.trim()) {
this.set('newName', '');
return;
}
@ninegrid
ninegrid / editable-area.hbs
Created March 16, 2014 09:27
An editable area... markdown is rendered normally... double tap with your finger and viola a text area to edit it
{{#if isEditing}}
{{textarea value=value focus-out='doneEditing'}}
{{else}}
<a style="cursor:pointer">{{format-markdown value}}</a>
{{/if}}
type RGB =
| Red of byte
| Green of byte
| Blue of byte
let (|TheRed|_|) = function
| Red x -> Some x
| _ -> None
let xs = [Red 42uy; Green 0uy; Blue 0uy]
@ninegrid
ninegrid / universe.fs
Last active March 26, 2016 14:03
1D 2-color cellular automata in F#
type cell = A | B
type 'cell U = U of 'cell LazyList * 'cell * LazyList<'cell>
module Universe =
open LazyList
let U left focus right = U (left, focus, right)
let initial () = U (repeat A) B (repeat A)
let shiftRight = fun (U (left,focus,Cons(focus',right))) -> U (cons focus left) focus' right

#r @"E:\Assemblies\OpenTK\OpenTK.dll"
open System
open System.Drawing
open System.Collections.Generic
open OpenTK
open OpenTK.Graphics
open OpenTK.Graphics.OpenGL

(* original sample data.. search/replaced symbols from python
dictionary of dictionaries *)
let criticsList = [
"Lisa Rose", [
"Lady in the Water", 2.5; "Snakes on a Plane", 3.5;
"Just My Luck", 3.0; "Superman Returns", 3.5;
"You; Me and Dupree", 2.5; "The Night Listener", 3.0
];
"Gene Seymour", [
// Learn more about F# at http://fsharp.net
namespace BasicConcepts
module Algorithms =
let ``1.1E`` (m : uint32) (n : uint32) =
let rec aux m n l =
let r = m % n
if r <> 0u then aux n r (r :: l) else l
aux m n [] |> Seq.head
#time
(fun _ ->
let initial =
seq { for x = 0 to 100 do
for y = 0 to 100 do
if (1 < x) && (x < y) && ((x + y) < 100) then
yield (x,y) }
Seq.iter (fun _ -> ()) initial
)()