Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Girard grabcode

View GitHub Profile
@grabcode
grabcode / FPSMonitor.js
Last active Aug 29, 2015
Snippet adding a surface showing the Famo.us engine FPS - written during Hello Famo.us lesson
View FPSMonitor.js
(function(target, engine, interval) {
var surface = new Surface({
size: [50, 35],
content: '',
properties: {
color: 'white',
textAlign: 'center',
backgroundColor: '#FA5C4F',
border: '1px solid black'
View backbone_fetch_monkeypatch.js.coffee
root = exports ? this
# Overloading backbone fetch method
previousFetch = Backbone.Collection.prototype.fetch
root.Backbone.Collection.prototype.fetch = (options={})->
asyncUniqId = _.uniqueId 'time_'+@constructor.name+'_'
console.time asyncUniqId
previousSuccess = if options? then options.success else undefined
options = _.extend(options,
success: =>
@grabcode
grabcode / _log.js.coffee
Created Feb 8, 2015
Isomorphic javascript helper - custom log
View _log.js.coffee
root = exports ? this
root._log = ->
args = [new Date()].concat Array.prototype.slice.apply(arguments)
console.log.apply console, args
View counter.scss
.custom-counter{
list-style-type: none;
&>li{
counter-increment: step-counter;
&:before{
content: counter(step-counter);
}
}
View meteor.cors.js
/*
Enable iron-router route to run cross-origin resource sharing
Usage:
Router.route('/ping', function(){
(new Cors(this)).respondWith({"oh": "yeah"});
}, {where: 'server'});
Note: dependency on underscore.js (what meteorjs app doesn't anyway ;)
*/
@grabcode
grabcode / stub.js.coffee
Created Aug 21, 2015
Underscore.js Mixin to stub an object methods - Useful when libraries are meant to work on a live environment (login exception for instance, with window.Rollbar)
View stub.js.coffee
# Usage: window.myObject = _.stub('myObject', {error: null, print: null})
_.mixin
stub: (objectName, props)->
res = {};
for prop of props
if props[prop]?
res[prop] = props[prop]
else
res[prop] = ((method)->
->
@grabcode
grabcode / snippets.cson
Last active Dec 28, 2015
ReactNative Component and Styles Snippet
View snippets.cson
'.source.js':
'ReactNative Component':
'prefix': 'rnc'
'body': """
'use strict';
import React, {
Text,
} from 'react-native';
@grabcode
grabcode / scope_explorer.js
Last active Feb 2, 2016
Explore or Spy the global variables available, or any given scope. By default, it run in the global browser scope `window`, and exclude its default properties.
View scope_explorer.js
/*
* Explore/Spy App Global variables, excluding defaults (defaults comes down a scope)
* > Run me in your dev tool console via copy/pasting
* > In return, I provide a list of keys, and copy in your clipboard (how sweet is that!)
*
* Follow my creator https://twitter.com/grabthecode
*/
;(function(scope, defaults){
@grabcode
grabcode / validCandidate.js
Last active Apr 12, 2016
validCandidate function
View validCandidate.js
function validCandidate(languages) {
let validCandidate = false
let languageRegex = /script$/
if(Array.isArray(languages)) {
validCandidate = !!languages.filter( (language)=> languageRegex.test(language) ).length
} else if (typeof languages == 'string') {
validCandidate = languageRegex.test(languages)
}
return validCandidate
}