Skip to content

Instantly share code, notes, and snippets.

class SomeAjaxCallback
constructor: (@value) ->
throw "Bad value" unless value?
setTimeout @process, 5000
# setTimeout doesn't give us a "new context"
# so we'd get our "global context" : window.
# let's avoid that using the fat arrow.
process: =>
throw "Wrong context" unless @value?
# ****
# Needs to be before the optional dependency
# ****
optional = (name) ->
try
require name
catch err
console.log " * optional dependency not found: #{name}"
false
@cjlyth
cjlyth / gulp-npm.js
Created April 8, 2014 19:27
simple example of using npm inside a grunt task
var gulp = require('gulp');
var npm = require("npm");
var pkg = require("./package.json")
gulp.task('default', [], function(cb){
npm.load(pkg, function (er, npm) {
// npm.config.set('global', true);
npm.commands.update([],cb);
});
});
bower install -V |& progress
@cjlyth
cjlyth / clean-logfiles.sh
Last active August 29, 2015 14:01
Snippet to redirect stderr and stdout to a file for a script
#!/usr/bin/env bash
find /tmp -maxdepth 1 -type f -uid $(id -u) -name "*err*.log" -delete
@cjlyth
cjlyth / piwik.js
Created June 12, 2014 17:35
AngularJS Piwik Service
"use strict";
angular.module("MyApp.services"/*, []*/)
.constant('piwikUrl', 'http://0.0.0.0/piwik')
.constant('piwikAuthToken', '0a0a00a0aa0a00000a00aaa0000a0a0')
.constant('piwikSiteUrl', 'http://myapp.mydomain.com')
.constant('piwikSiteName', 'MyApp')
.service('piwik', ['$q', '$http', 'piwikUrl', 'piwikAuthToken', 'piwikSiteUrl', 'piwikSiteName',
function($q, $http, piwikUrl, piwikAuthToken, piwikSiteUrl, piwikSiteName) {
function fetchSiteIds (){
var deferred = $q.defer();
@cjlyth
cjlyth / serve-dir
Created June 17, 2014 01:58
This gist can be used to serve a directory using the http-server nodejs module
#!/usr/bin/env bash
DATA_DIR="$( cd ${1:-.} && pwd )"
[[ -d "${DATA_DIR?}" ]] || {
echo "Unable to find directory: ${DATA_DIR}"
exit 1
}
CONTAINER_NAME="$(basename ${2:-${DATA_DIR}})"
docker restart ${CONTAINER_NAME?} &> /dev/null && {
echo "Docker container '${CONTAINER_NAME}' restarted"
} || {
@cjlyth
cjlyth / demo.html
Last active August 29, 2015 14:02
angular directive that sync's a model to a scope var using a custom control
<pre>{{myObj | json}}</pre>
<pre>{{myProperty | json}}</pre>
<input ng-model="myObj.myVal" type="text" ></test>
<input ng-model="myObjVal" type="text" ></test>
<div bind-property="myObjVal" ng-model="myObj.myVal"></div>
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit | xargs tar -rf $commit.tar
@cjlyth
cjlyth / base16-build.sh
Created January 27, 2015 20:18
Base16 Build with Docker
git clone git@github.com:chriskempson/base16-builder.git
cd base16-builder
docker run -it --rm --name base16-builder \
-v "$(pwd)":/usr/src/base16-builder \
-w /usr/src/base16-builder \
ruby /usr/src/base16-builder/base16