Skip to content

Instantly share code, notes, and snippets.

View grabcode's full-sized avatar

Alex Girard grabcode

View GitHub Profile
@grabcode
grabcode / validCandidate.js
Last active April 12, 2016 00:01
validCandidate function
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
}
@grabcode
grabcode / scope_explorer.js
Last active February 2, 2016 10:38
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.
/*
* 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 / snippets.cson
Last active December 28, 2015 03:27
ReactNative Component and Styles Snippet
'.source.js':
'ReactNative Component':
'prefix': 'rnc'
'body': """
'use strict';
import React, {
Text,
} from 'react-native';
@grabcode
grabcode / stub.js.coffee
Created August 21, 2015 04:16
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)
# 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 / meteor.cors.js
Created May 29, 2015 10:08
Iron Router CORS
/*
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 / counter.scss
Created April 8, 2015 05:11
CSS Counter
.custom-counter{
list-style-type: none;
&>li{
counter-increment: step-counter;
&:before{
content: counter(step-counter);
}
}
@grabcode
grabcode / _log.js.coffee
Created February 8, 2015 00:38
Isomorphic javascript helper - custom log
root = exports ? this
root._log = ->
args = [new Date()].concat Array.prototype.slice.apply(arguments)
console.log.apply console, args
@grabcode
grabcode / backbone_fetch_monkeypatch.js.coffee
Last active August 29, 2015 14:11
Timing backbone fetch
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 / FPSMonitor.js
Last active August 29, 2015 13:59
Snippet adding a surface showing the Famo.us engine FPS - written during Hello Famo.us lesson
(function(target, engine, interval) {
var surface = new Surface({
size: [50, 35],
content: '',
properties: {
color: 'white',
textAlign: 'center',
backgroundColor: '#FA5C4F',
border: '1px solid black'