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 / Autocomplete.scss
Last active August 29, 2015 14:23
Basic Autocomplete Widget
@mixin li-hover {
background: #3875d7;
color: #fff;
}
.autocomplete-input--select-drop {
background: white;
border: 1px solid #aaa;
margin-top: -1px;
position: absolute;
@gilbert
gilbert / gist:0cfa65ce832ce35a278e
Last active March 27, 2017 09:06
Global AJAX loading indicator for Mithril.js
(function () {
//
// Global ajax loaders
//
// This is useful for showing a loading animation, yet still taking
// advantage of the default behavior of m.request, which is to wait
// for all requests to complete before rendering the view.
//
// The loader is assumed to already be on the page
var loader = document.querySelector('.ajax-loader')
@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
@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 / 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 / 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 / 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 / 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 })
])
},
// 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 / 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([