Skip to content

Instantly share code, notes, and snippets.

@wishfoundry
wishfoundry / fork.js
Created August 24, 2012 18:56
Node unix socket worker process
if (cluster.isMaster) {
var cpus = os.cpus().length;
var worker;
/* start up the HTTP servers */
process.env.HTTP_WORKER = "1";
for (var i = 0; i < cpus; i++) {
worker = cluster.fork();
worker.isHTTP = true;
}
@wishfoundry
wishfoundry / gist:4126316
Created November 21, 2012 17:34
image resize
if ($image_w < $image_h)
{
//portrait
$height = $max_height;
$width = round( $height*($image_w/$image_h) );
}
if($image_w => $image_h)
{
//landscape
if($image_h < ($image_w/2))
@wishfoundry
wishfoundry / Laravel 4 Trailing slashes
Created January 17, 2013 20:45
Match any route with a trailing slash and redirect to the correct one
Route::get('{any}', function($url){
return Redirect::to(mb_substr($url, 0, -1), 301);
})->where('any', '(.*)\/$');
# Load dependencies.
pmodload 'helper'
CURRENT_BG='NONE'
SEGMENT_SEPARATOR='⮀'
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
@wishfoundry
wishfoundry / gist:6907655
Created October 9, 2013 20:19
quick links for jshinting
http://travisjeffery.com/b/2013/09/testing-javascript-projects-with-grunt-jasmine-jshint/
https://github.com/gruntjs/grunt-contrib-jshint
https://github.com/bkeepers/lucid/blob/master/spec/javascripts/z_jshint_spec.js
@wishfoundry
wishfoundry / gist:7036457
Last active April 1, 2022 05:18
Set OSX default text editor to sublime text 3 instead of TextEdit
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'
@wishfoundry
wishfoundry / doctype switcher
Last active December 29, 2015 01:19
Having trouble with xml based templating engines that don't allow you to declare a modern doctype? Use this little snippet to dynamically switch it to something sane!
<script>
(function switchToHTML5() {
// create an html5 doctype
var newDoctype = document.implementation.createDocumentType('html', '', '');
if (document.doctype) {
document.doctype.parentNode.replaceChild(newDoctype, document.doctype);
} else {
var currentHtml = document.head.parentNode;
currentHtml.parentNode.insertBefore(newDoctype, currentHtml)
@wishfoundry
wishfoundry / decorate angular directive example 1
Created January 12, 2014 16:56
experimenting with ways to decorate angular directives. The disadvantage here is you apply this to all directives
app.config(function($provide) {
$provide.decorator('fooDirective', function($delegate) {
var directive = $delegate[0];
if(directive.restrict.indexOf('E') >= 0) {
makeElement(toDashCase(name))
}
function toDashCase(str) {
return (str.charAt(0) + string.slice(1).replace(/([A-Z])/g, "-$&")).toLowerCase()
@wishfoundry
wishfoundry / decorating angular directives 2
Created January 12, 2014 17:03
still experimenting with extending directive, this time more globally. This is a bit of a hack really
(function(undefined){
var oldDir = angular.module('app').directive;
angular.module('app').directive = function(name, dFactory) {
var dir = oldDir(name, dFactory);
if(dir.restrict.indexOf('E') >= 0) {
makeElement(toDashCase(name))
}
};
/*
$stateProvider.state('admin', {
url: '/admin',
data:{
title: 'Logout',
only: 'admin'
},
templateUrl: URL.toPartial('logout')
})