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
@gilbert
gilbert / artists.js
Created December 25, 2014 02:54
Spotify API with Mithril.js Promises
// Use like the following:
// fetchArtistProfiles(names).then(vm.artist_profiles)
function fetchArtistProfiles (artistNames) {
var promises = artistNames.map(function (name) {
return fetchArtist(name)
.then(fetchTracks)
.then(buildProfile.curry(name))
})
return m.sync(promises)
@gilbert
gilbert / instructions.md
Created December 16, 2014 20:13
Pulling a Heroku Postgres DB

Pulling a Heroku Postgres DB

Add the following to your .bash_profile / .profile / whatever:

function heroku_pg_pull(){
  echo "!   WARNING: Data in the local database '$2' will be destroyed."
  echo "    Type '$2' to overwrite data in local database '$2'"
  read -p "> " local_database_name
 echo
@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
@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 / 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
var myData = [
{
week: 1,
count: 5
},
{
week: 2,
count: 1
},
{
@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
@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 / 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 / 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)