Skip to content

Instantly share code, notes, and snippets.

View git-squash-last-3-commits
git reset --soft HEAD~3 && git commit -m"Squashing last 3 commits"
@bjdixon
bjdixon / Replace_partial_string_in_MySQL
Last active Aug 29, 2015
Replace one string with another for all rows in a field
View Replace_partial_string_in_MySQL
UPDATE DBNAME.TableName
SET DBNAME.TableName = REPLACE(DBNAME.TableName.FieldName,'OldString','NewString')
WHERE DBNAME.TableName.FieldName like '%OldString%';
@bjdixon
bjdixon / app.js
Created Aug 30, 2014 — forked from tj/app.js
cookie based sessions using express
View app.js
var express = require('express')
, cookieSessions = require('./cookie-sessions');
var app = express();
app.use(express.cookieParser('manny is cool'));
app.use(cookieSessions('sid'));
app.get('/', function(req, res){
req.session.count = req.session.count || 0;
@bjdixon
bjdixon / is_array.js
Last active Aug 29, 2015
Check if value is an array or not in javascript
View is_array.js
// typeof operator reports arrays as 'object'
// this function can be used to determine if the value is an array or not.
var is_array = function (value) {
return Object.prototype.toString.apply(value) === '[object Array]';
};
var ar1 = ['abc', 'def', 'hij']; // array
var ob1 = {'0': 'abc', '1': 'def', '2': 'hij'}; // object
var va1 = 'abcdefhij'; // string
@bjdixon
bjdixon / ng-cloak
Created Sep 21, 2014
css for using ng-cloak directive
View ng-cloak
[ng\:cloak], [ng-cloak], [data-ng-cloak], .ng-cloak, .x-ng-cloak {
display: none;
}
@bjdixon
bjdixon / upgrade_node_with_npm
Created Jan 27, 2015
Upgrade node version using npm
View upgrade_node_with_npm
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
node -v
@bjdixon
bjdixon / jquery.exists
Created Apr 27, 2015
Extend jquery with function to check if an element exists
View jquery.exists
//extend jquery with function to check if element exists
$.fn.exists = function(){
return this.length > 0 ? this : false;
}
//usage
$('.matchme').exists(); //returns reference to element if exists otherwise false
@bjdixon
bjdixon / list_events.js
Created Jun 3, 2015
List all events registered to a particular element
View list_events.js
$._data( $(selector)[0], "events" );
@bjdixon
bjdixon / combinators.js
Last active Aug 29, 2015
Combinators in JavaScript (ES6)
View combinators.js
// Kestrel
const K = ( x ) => ( y ) => x;
// Identity
const I = ( x ) => x;
// Vireo
const V = ( x ) => ( y ) => ( z ) => z( x )( z );
// Thrush
const T = ( x ) => ( y ) => y( x ), x;
// Why
const Y = ( x ) => ( ( y ) => y( y ) )( ( y ) => ( x( ( z ) => y( y )( z ) ) ) );
@bjdixon
bjdixon / memo.js
Last active Aug 29, 2015
Memoize a function
View memo.js
memo = function (fn) {
var cache = {};
return function () {
var key = JSON.stringify(this, arguments);
return cache[key] || (cache[key] = fn.apply(this, arguments));
}
}
You can’t perform that action at this time.