Skip to content

Instantly share code, notes, and snippets.

View gilbert's full-sized avatar
🪐
Security in space

Gilbert gilbert

🪐
Security in space
View GitHub Profile
Step 1: Create the cheatsheet.
var itemTemplateSource = $('#templates .item').html()
var itemTemplate = _.template(itemTemplateSource);
var AddItemView = Backbone.View.extend({
events: {
'submit': 'createItem'
},
createItem: function (e) {
e.preventDefault();
var itemName = this.$('.name').val();
@gilbert
gilbert / curry.rb
Last active August 29, 2015 14:05
[Practical] Partial Application in Ruby
require 'deterministic'
class X
include Deterministic
def go
# The `>>` is from Deterministic. It feeds the result
# of the left side into the right side.
# get_num >> mcurry(:add, 1) >> mcurry(:double)
@gilbert
gilbert / book.rb
Created September 3, 2014 20:39
Rails forms
class Book < ActiveRecord::Base
validates :name, :presence => true
validates :published_at, :presence => true
end
@gilbert
gilbert / index.html.erb
Created September 8, 2014 17:40
DoubleDog Many-to-Many From
<h2>Create New Order</h2>
<% if @error %>
<p>Error: <%= @error %> </p>
<% end %>
<%= form_tag orders_path, :method => :post do %>
<!-- Our goal is to an array of item ids -->
<select class="item-select" name="order[item_ids][]">
@gilbert
gilbert / no-comments.rb
Last active August 29, 2015 14:06
Arrow Programming Language Sketch
module Library do
record Author do
fields do
name :: String
end
name :: Book -> String
name { author: authorName } = authorName
end
var myData = [
{
week: 1,
count: 5
},
{
week: 2,
count: 1
},
{
@gilbert
gilbert / Entry.js
Last active December 6, 2018 22:46
Event Volunteers: Mithril.js Example from Tutorial Part 1 http://gilbert.ghost.io/mithril-js-tutorial-1/
//
// A model representing an Entry
//
window.Entry = {}
var store = []
var idCounter = 1
Entry.all = function () {
return store
@gilbert
gilbert / functions.js
Last active September 20, 2016 15:09
JavaScript Function Extensions
// Partially apply arguments to a function. Useful for binding
// specific data to an event handler.
// Example:
//
// var add = function (x,y) { return x + y }
// var add5 = add.papp(5)
// add5(7) //=> 12
//
Function.prototype.papp = function () {
var slice = Array.prototype.slice
@gilbert
gilbert / description.txt
Last active August 29, 2015 14:09
Hamming Distance Exercise
# Hamming
Write a program that can calculate the Hamming difference between two DNA strands.
A mutation is simply a mistake that occurs during the creation or
copying of a nucleic acid, in particular DNA. Because nucleic acids are
vital to cellular functions, mutations tend to cause a ripple effect
throughout the cell. Although mutations are technically mistakes, a very
rare mutation may equip the cell with a beneficial attribute. In fact,
the macro effects of evolution are attributable by the accumulated