Skip to content

Instantly share code, notes, and snippets.

View mlegenhausen's full-sized avatar

Malte Legenhausen mlegenhausen

View GitHub Profile
@chanon
chanon / gist:661597
Created November 3, 2010 19:50
Facebook iframe Canvas App Authentication in node.js
var querystring = require("querystring");
var base64ToString = function(str) {
return (new Buffer(str || "", "base64")).toString("ascii");
};
var base64UrlToString = function(str) {
return base64ToString( base64UrlToBase64(str) );
};
@bgerrissen
bgerrissen / gist:715141
Created November 25, 2010 09:52
RequireJS cacheKey

reason

Offers a simple mechanism to allow extremely long expire-headers on scripts whilst still being able to switch to newer versions on the fly.

implementation

A js file defined with data-main attribute on the script tag of require.js, will always be loaded with current timestamp to always force a fresh load.

// main.js?cacheKey=TIMESTAMP-123412312321
@tokland
tokland / underscore_extensions.js
Created September 16, 2011 16:28
My extensions for underscore.js
_.mixin({
/* Like extend but get key/values object->key_names */
extend_from: function(object, source_object, key_names) {
return _(object).extend(_(source_object).slice(key_names));
},
/* Return a new object with the merged properties of all objects in arguments */
merge: function() {
var objects = arguments;
return _.reduce(_.rest(objects), function(obj, o) {
@arian
arian / crop.js
Created August 5, 2012 19:33
Cropping images with nodejs streams and imagemagick
var spawn = require('child_process').spawn;
var Stream = require('stream');
/**
* crops and resizes images to our desired size
* @param {Stream} streamIn in stream containing the raw image
* @return {Stream}
*/
exports.cropImage = function(streamIn){
@caseman
caseman / gist:3428752
Created August 22, 2012 19:49
Ctor: Lightweight Javascript Constructors with Inheritance

Ctor: Lightweight Javascript Constructors with Inheritance

Author: Casey Duncan @iamnotcasey

This Javascript constructor with inheritance pattern is designed as a lightweight alternative to other methods I've seen while still providing a nice abstraction as a 13 line function that can be easily inlined into your code.

@yonekawa
yonekawa / CDVViewController.m.patch
Created October 3, 2012 01:08
Fix PhoneGap2.1-iOS does not work with RequireJS
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index a0a29f0..520050d 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -510,7 +510,7 @@
// The iOSVCAddr is used to identify the WebView instance when using one of the XHR js->native bridge modes.
// The .onNativeReady().fire() will work when cordova.js is already loaded.
// The _nativeReady = true; is used when this is run before cordova.js is loaded.
- NSString* nativeReady = [NSString stringWithFormat:@"cordova.iOSVCAddr='%lld';try{cordova.require('cordova/channel').onNativeReady.fire();}catch(e){window._nativeReady = true;}", (long long)self];
+ NSString* nativeReady = [NSString stringWithFormat:@"window.iOSVCAddr='%lld';try{cordova.require('cordova/channel').onNativeReady.fire();}catch(e){window._nativeReady = true;}", (long long)self];
@amatiasq
amatiasq / new.js
Created December 10, 2013 15:45
A simple .new() method to create instances without constructors. This allow us to rewrite the "new" in order to do other things but create objects.
function $new() {
var obj = Object.create(this);
obj.init.apply(obj, arguments);
return obj;
}
@sindresorhus
sindresorhus / post-merge
Last active May 2, 2024 03:18
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
#!/bin/bash
# This script automatically sets the version and short version string of
# an Xcode project from the Git repository containing the project.
#
# To use this script in Xcode, add the script's path to a "Run Script" build
# phase for your application target.
set -o errexit
set -o nounset
@rewoo
rewoo / my-awesome-directive.js
Last active January 3, 2018 09:33
Automatic unbind pattern for event bindings in directives using AngularJS
angular.module('app', [])
.directive('myAwsomeDirective', function($rootScope) {
return {
restrict: 'A',
link: function(scope) {
// $scope.$on() returns an unbind function of the binding
//
// So use the bind function directly within scope's $destroy event
// to unbind event automatically.
scope.$on('$destroy', $rootScope.$on('my:event', function() {