Skip to content

Instantly share code, notes, and snippets.

View drphrozen's full-sized avatar

Esben Sune Rasmussen drphrozen

View GitHub Profile
@drphrozen
drphrozen / eachWait.js
Created August 23, 2012 06:14
eachWait for jQuery ($.each with setTimeout)
(function( $ ) {
$.eachWait = function(arr, callback, interval, bulksize) {
interval = interval || 10;
bulksize = bulksize || 10;
var index = 0;
var intervalObj = setInterval(function() {
for(var j = 0; j<bulksize; j++) {
if (index < arr.length) {
try {
callback(index, arr[index]);
@drphrozen
drphrozen / Handlers.js
Created August 29, 2012 11:00
Using Javascript and ASP.NET MVC
// using jQuery
// NS is just some global namespace, replace as you see fit
NS = {
init: function() {
var mvcContext = $('body').data('controller-and-action');
NS.Context.controller = mvcContext.controller.toLowerCase();
NS.Context.action = mvcContext.action.toLowerCase();
var callIfFunction = function(arg) { if ($.isFunction(arg)) { arg(); } };
@drphrozen
drphrozen / LessBundle.cs
Created September 26, 2012 06:54
LessBundle
public class LessBundle : Bundle
{
public LessBundle(string virtualPath) : base(virtualPath, new LessTransform(), new CssMinify()) { }
}
public class LessTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
var sb = new StringBuilder();
@drphrozen
drphrozen / ng-minify-example.js
Created November 6, 2012 08:12
AngularJS minification
angular.module('SampleModule', [])
.factory('SampleService', ['$resource', function(resource) {
// ...
})
.controller('SampleController', ['$scope', '$resource', function(scope, resource) {
// ...
});
// Alternative notation using $inject:
@drphrozen
drphrozen / DocumentEventsModule.js
Created November 16, 2012 10:37
AngularJS directives for the document element. Usage doc-click, doc-*. Check ng-click and ng-* for documentation :-)
var dem = angular.module('DocumentEventsModule', []);
angular.forEach(['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout', 'mousemove', 'mouseenter', 'mouseleave'], function(name) {
var capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);
var directiveName = 'doc' + capitalizedName;
dem.directive(directiveName, ['$parse', '$document', function(parse, document) {
return function(scope, element, attr) {
var fn = parse(attr[directiveName]);
document.bind(name, function(event) {
scope.$apply(function() {
angular.module('LocalCacheModule', []).
factory('LocalCache', ['$q', '$log', function(q, log) {
var retrievers = {};
var ttls = {};
var localCache = {
retrieve: function(key, ready) {
var retriever = retrievers[key];
if (angular.isFunction(retriever)) {
retriever(function(data) {
localCache.put(key, data);
if (typeof String.prototype.decodeEntities == 'undefined') {
(function () {
// this prevents any overhead from creating the object each time
var element = document.createElement('div');
String.prototype.decodeEntities = function () {
var str = this;
// strip script/html tags
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
element.innerHTML = str;
@drphrozen
drphrozen / dumpObject.js
Last active December 16, 2015 21:38
This will dump an object, skip functions and objects starting with DOM or HTM
function dumpObject(root, indent){
if(indent == null) indent = " ";
function toType(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1];
}
var queue = [{ data: root, level: 0 }];
function add(data, level, prepend) {
queue.push({data: data, level: level, prepend: prepend});
@echo off
set HANDBRAKE="C:\Program Files\Handbrake\HandBrakeCLI.exe"
for /r %%a in (*.avi *.mkv *.wmv *.divx *.mpg *.mpeg *.m4v *.ogg) do %HANDBRAKE% -i "%%~a" -o "%%~dpna_.mkv" -e x264 -q 20 -E faac -B 128 --x264-preset medium --x264-profile main -x level=4.0
@drphrozen
drphrozen / EnvironmentColors.html
Last active December 24, 2015 08:29
Visual Studio 2012 EnvironmentColors
<html ng-app>
<head>
<title>Visual Studio 2012 Colors</title>
<style>
body > p > span {
width: 90px;
border: 2px solid black;
display: inline-block;
font: 10pt 'Courier New', 'Courier', 'monospace';
text-align: center;