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 / 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 / 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 / index.html
Created January 16, 2015 16:22
Quizzy Part 1 MVC w/ Mithril.js
<html>
<head>Quizzy Part 1 MVC</head>
<body>
<div id="app"></div>
<script src="vendor/mithril.js" type="text/javascript"></script>
<script src="quiz.js" type="text/javascript"></script>
<script type="text/javascript">
Quiz.vm.questions([
// English Example:
// Do your daily duties:
// Make me breakfast
// Do my laundry
// Walk my dog
// Make me breakfast:
// Turn on the stove
// Get out the eggs
@gilbert
gilbert / widget.js
Created March 25, 2015 17:09
Mithril + JSS
Widget = {
controller: function () {
this.css = Widget.stylesheet().classes
},
view: function (ctrl) {
return m('.widget', [
m('h3', { class: ctrl.css.head }),
m('div', { class: ctrl.css.body })
])
},
@gilbert
gilbert / component-sugar.js
Last active August 29, 2015 14:17
Mithril Component Sugar
m.callableComponent = function (componentObj) {
var componentFn = function (props, content) {
return m.component(componentFn, props, content)
}
if (componentObj) {
for (var prop in componentObj) {
componentFn[prop] = componentObj
}
}
return componentFn
@gilbert
gilbert / obind.js
Created March 27, 2015 18:59
JavaScript Partial Application with Objects
// NOTE: Requires Object.assign (you might need a polyfill)
Function.prototype.obind = function (ctx, obj) {
var f = this
var args = arguments
return function () {
arguments[0] = Object.assign(obj, arguments[0])
return f.apply(ctx, arguments)
}
}
@gilbert
gilbert / globals.js
Last active August 29, 2015 14:17
Global Function Helpers
(function (global) {
global.getProp = function (propName) {
return function (obj) { return obj[propName] }
}
global.queryProp = function (query) {
var segments = query.split('.')
return function (obj) {
var result = obj
@gilbert
gilbert / m.ext.js
Last active August 29, 2015 14:18
Mithril.js Extensions
m.deferred.resolve = function (value) {
var deferred = m.deferred()
deferred.resolve(value)
return deferred.promise
}
m.deferred.reject = function (value) {
var deferred = m.deferred()
deferred.reject(value)
return deferred.promise
@gilbert
gilbert / Coupon.js
Last active October 2, 2015 19:27
Mithril.js Tutorial Part 2
window.Coupon = {}
Coupon.controller = function (attrs) {
var ctrl = this
ctrl.code = ""
ctrl.submit = function (e) {
e.preventDefault()
ctrl.error = null