Skip to content

Instantly share code, notes, and snippets.

@shama
shama / a_simple.js
Created September 17, 2012 16:38
Grunt Events
/*
* A) Simple Watch Events
*/
module.exports = function(grunt) {
grunt.initConfig({
nodeunit: {
files: ['test/**/*.js'],
},
watch: {
test: {

Problem

Some tasks utilize the watch to trigger an event, ie: live reload. With Grunt v0.3, those tasks on first run would create a variable, ie servers. Then subsequently ran by the watch task would check if the variable exists and then use it. Since the new watch spawns tasks, this is no longer possible.

Solutions Proposed

A) Have watch trigger a grunt.event

@andrewgleave
andrewgleave / ContentEditableLabel.js
Last active September 15, 2016 09:32
An editable React.js label element based on the contenteditable attribute
/** @jsx React.DOM */
'use strict';
var React = require('react');
var ContentEditableLabel = React.createClass({
propTypes: {
tag: React.PropTypes.func,
@thomseddon
thomseddon / gist:4703810
Last active December 27, 2016 02:58 — forked from nobuf/gist:3419910
Supporting placeholder on IE9 with AngularJS (without jQuery) > Removed jQuery dependency > Slight optimisation in retrieving placeholder text
angular.module('test', [])
.directive('placeholder', function($timeout){
var i = document.createElement('input');
if ('placeholder' in i) {
return {}
}
return {
link: function(scope, elm, attrs){
if (attrs.type === 'password') {
return;
@sebcode
sebcode / gist:4a43760ab4abaf078f987f1dd94d4178
Created April 6, 2017 18:17
Replace @autoBind decorator with class instance properties
// https://github.com/andreypopp/autobind-decorator
// https://github.com/facebook/codemod
// Example replacement:
// - @autobind onClick(e: SyntheticEvent) {
// + onClick = (e: SyntheticEvent) => {
codemod -m -d . --extensions js \
'@autobind\ ([a-zA-Z0-9]+)\(([^)]*)\)' \
'\1 = (\2) =>'
@cpetschnig
cpetschnig / validate_ipv6.rb
Created February 4, 2010 09:19
Regular Expression Validation for IPv6 Addresses in Ruby
# Regular Expression Validation for IPv6 addresses in Ruby
#
# Inspired by (if not to say copied from): http://forums.dartware.com/viewtopic.php?t=452
# Thanks, Dartware!
IPV6_REGEX = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f
@mdaniel
mdaniel / Vagrantfile
Last active February 21, 2021 10:30
Provision a virtual machine for building ChromeOS using Vagrant <http://www.vagrantup.com>. Just download this into a directory, name it ``Vagrantfile`` (if it isn't already), run ``vagrant up`` followed by ``vagrant ssh`` and you'll see two shell scripts there, ready to sync up the ChromeOS source code.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu1204_64"
@admackin
admackin / .bashrc
Last active February 10, 2022 22:06
Sane SSH_AUTH_SOCK handling for Screen and Tmux, so that new SSH agents created by subsequent logons are still usable.
_ssh_auth_save() {
ln -sf "$SSH_AUTH_SOCK" "$HOME/.ssh/ssh-auth-sock.$HOSTNAME"
}
alias screen='_ssh_auth_save ; export HOSTNAME=$(hostname) ; screen'
alias tmux='_ssh_auth_save ; export HOSTNAME=$(hostname) ; tmux'
@jsdf
jsdf / immutableJSFormatter.js
Last active May 19, 2022 10:51
Chrome devtools formatter for Immutable-js
const immutableJSFormatter = {
header(x) {
if (x && x.toJS) return ['span', {}, x.toString()];
return null;
},
hasBody(x) {
return x && x.toJS;
},
body(x) {
return ['span', {}, JSON.stringify(x.toJS(), null, 2)];