Skip to content

Instantly share code, notes, and snippets.

@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>
@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 / 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 / colors.sh
Last active September 29, 2022 00:51
Shell script to start my docker containers while im developing
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
[[ -f "$DIR/colors.tput.sh" ]] && {
source "$DIR/colors.tput.sh"
} || {
echo "Unable to find file: $DIR/colors.tput.sh"
exit 1
}
reset="$(color)"
@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
bower install -V |& progress
@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);
});
});
# ****
# Needs to be before the optional dependency
# ****
optional = (name) ->
try
require name
catch err
console.log " * optional dependency not found: #{name}"
false
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?
@cjlyth
cjlyth / cors.js
Created November 19, 2013 20:43
CORS support for express
api.all('*', function(req, res, next){
if (!req.get('Origin')) return next();
// use "*" here to accept any origin
res.set('Access-Control-Allow-Origin', 'http://localhost:3000');
res.set('Access-Control-Allow-Methods', 'GET, POST');
res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
// res.set('Access-Control-Allow-Max-Age', 3600);
if ('OPTIONS' == req.method) return res.send(200);
next();