Skip to content

Instantly share code, notes, and snippets.

@tastywheat
tastywheat / UIrouterReloadOnSearchWorkaround.js
Created November 20, 2013 17:18
ui router reloadOnSearch workaround
.run(function($rootScope){
// register listener to watch route changes
$rootScope.$on( "$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {
if ( fromState.name === "watch" && fromState.name === toState.name) {
//do nothing, prevent page reload
event.preventDefault();
}
});
})
@tastywheat
tastywheat / scrollToElement.js
Created December 22, 2013 00:37
Angular directive: action on rollover element
<!doctype html>
<html ng-app='app'>
<head>
<style>
body{
height:5000px;
}
.block{
height:300px;
.open > .dropdown-menu {
-webkit-transform: scale(1, 1);
transform: scale(1, 1);
}
.open > .dropdown-menu li a {
color: #000;
}
.dropdown-menu li a{
color: #fff;
var redis = require("redis")
, subscriber = redis.createClient()
, publisher = redis.createClient();
subscriber.on("message", function(channel, message) {
console.log("Message '" + message + "' on channel '" + channel + "' arrived!")
});
subscriber.subscribe("test");
@tastywheat
tastywheat / pubsub.js
Last active August 29, 2015 13:55
pubsub.js
var App = {};
App.cache = {};
App.uniqueId = 0;
App.publish = function(channel, data){
for(var index in App.cache[channel])
App.cache[channel][index](data);
}
App.subscribe = function(channel, handler){
@tastywheat
tastywheat / express-consolidate-template.js
Last active August 29, 2015 13:56
express-consolidate-template.js
var express = require('express')
, cons = require('consolidate')
, app = express();
// assign the swig engine to .html files
app.engine('html', cons.swig);
// set .html as the default extension
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
http://nginx.org/en/docs/beginners_guide.html
@tastywheat
tastywheat / revealing-module-init.js
Last active August 29, 2015 13:56
revealing module with init
(function(){
var init = _.once(function(){
});
return {
init: init
};
})().
@tastywheat
tastywheat / object-cache-syncronization.html
Last active August 29, 2015 13:56
object cache syncronization
<html>
<body>
<script>
var cacheService = function(){
var cache = {};
function get(key){
return cache[key];
}
@tastywheat
tastywheat / requestAnimationFrame.js
Last active August 29, 2015 13:57
request animation frame
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|| window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)