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 / DefaultKeyBinding.dict
Created February 17, 2017 05:14
Enable terminal text navigation keyboard shortcuts across entire OS X operating system
/* Create a new file at ~/Library/KeyBindings/DefaultKeyBinding.dict */
/* and copy/paste this into it. */
{
"~f"="moveWordForward:";
"~b"="moveWordBackward:";
"~<"="moveToBeginningOfDocument:";
"~>"="moveToEndOfDocument:";
"~v"="pageUp:";
"~d"="deleteWordForward:";
"~^h"="deleteWordBackward:";
@gilbert
gilbert / keybase.md
Last active September 29, 2017 18:12

Keybase proof

I hereby claim:

  • I am gilbert on github.
  • I am mindeavor (https://keybase.io/mindeavor) on keybase.
  • I have a public key whose fingerprint is 7DB8 DF5F 0720 815C 104C 416A F8BA C5DA 9D8C 1B56

To claim this, I am signing this object:

@gilbert
gilbert / definition.js
Last active August 5, 2016 18:07
Expand / Collapse Animation with Mithril v1.x
var animateHeight = {
oncreate: function (vnode) {
var height = vnode.dom.clientHeight
vnode.dom.style.maxHeight = 0
vnode.dom.offsetHeight // Trick to recalc layout
window.requestAnimationFrame( ()=> (vnode.dom.style.maxHeight = height+1+"px") )
},
onbeforeremove: function (vnode, done) {
vnode.dom.addEventListener('transitionend', done)
vnode.dom.style.maxHeight = 0
@gilbert
gilbert / example.html
Created June 7, 2016 19:24
JavaScript DOM: Render line numbers on pre with no dependencies
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="line-numbers.css">
</head>
<body>
<pre><code>function add (a, b) {
return a + b;
}</code></pre>

Exercise 1.1

Draw a diagram of the result of following code.

var businessName = "Trader Joe's";
var location     = "Austin";

Exercise 1.2

@gilbert
gilbert / example-use.js
Last active August 18, 2016 13:44
Back-button & forward-button compatible Redux-like state management for Mithril.js
var BlogComments = {}
BlogComments.controller = function (options) {
App.state.fetch('blogComments', `/api/blog-post/${ options.blog_id }/comments`)
}
BlogComments.view = function (ctrl, options) {
var comments = App.state.blogComments
return m('.blog-comments-component', [
@gilbert
gilbert / view-model-example.js
Last active October 6, 2019 23:39
Mithril View-Model Example
var Comment = {]
Comment.create = function (attrs) {
return m.request({ method: 'POST', url: '/comments', data: attrs })
}
// A view-model is basically a temporary, disposable copy of a model.
// It allows the user can either commit or cancel the changes they make.
Comment.vm = function (attrs) {
attrs = attrs || {}
@gilbert
gilbert / example.js
Last active August 3, 2016 21:19
Mithril.js - Avoiding m.props
// m.prop is a great pattern, but Plain-old JavaScript Objects (POJO) are
// much more pleasant to work with.
// Here's an example of using POJOs with one- and two-way data binding.
// First, the helper methods
m.setValue = function (obj, prop) {
return m.withAttr('value', function(value) { obj[prop] = value })
}
@gilbert
gilbert / comment-model.js
Last active March 31, 2018 19:38
Mithril-friendly Model Layer
var Comment = {}
Comment.store = Store('Comment')
Comment.fetchForPost = function (postId) {
return m.request({ method: 'GET', url: '/api/post/' + postId + '/comments' })
.then(Comment.store.syncAll)
}
@gilbert
gilbert / ajax-loader.scss
Created July 8, 2015 16:15
Global Mithril.js AJAX Loader
// Taken from http://loading.io/
uiload {
display: inline-block;
position: relative;
& > div {
position: relative;
}
}
@-webkit-keyframes ajax-loader {