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 / 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>

Another file

@gilbert
gilbert / showcase.rb
Last active March 10, 2020 23:55
Minimal "states" mixin in Ruby
module HasStates
def state_field(column, state_names)
state_names.each do |name|
define_method("#{name}?") do
self.send(column) == name
end
end
end
end
@gilbert
gilbert / dogs.pl
Created January 24, 2020 06:54
Prolog learning
dog(rover).
dog(felix).
dog(benny).
has_owner(rover).
has_owner(benny).
is_happy(Dog) :- has_owner(Dog).
is_happy(Dog) :- breed(Dog, poodle).
@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 / stub.ts
Last active September 17, 2019 20:46
Concurrency-safe stubbing for TypeScript / Node.js
type QueueItem = {
filename: string
resolve: () => void
originalValue: any
stubValue: any
}
type Stub = {
queue: QueueItem[]
filename: string
originalValue: any
@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 / 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 / DefaultKeyBinding.dict
Last active February 27, 2018 11:30
Add missing keyboard shortcuts on OS X
/*
Create this as a file ~/Library/KeyBindings/DefaultKeyBinding.dict
Then restart your computer.
NOTE: ~ means alt/option
^ means ctrl
*/
{
"~f"="moveWordForward:";
"~b"="moveWordBackward:";
"~<"="moveToBeginningOfDocument:";
@gilbert
gilbert / showcase.jsx
Created February 12, 2018 13:50
JSX Formatting Tips
class Showcase extends React.Component {
constructor(props) {
super(props)
this.state = { ... }
}
toggle() {
this.setState({ open: ! this.state.open })
}
render() {
var {open, loading} = this.state