Skip to content

Instantly share code, notes, and snippets.

@bjdixon
bjdixon / remove_pyc_from_git
Created May 20, 2014 17:01
Because sometimes I forget to exclude .pyc until after I've tracked a couple
git rm --cached *.pyc
or
git update-index --assume-unchanged *.pyc
@bjdixon
bjdixon / git-squash-last-3-commits
Created June 27, 2014 02:59
Squash last n commits
git reset --soft HEAD~3 && git commit -m"Squashing last 3 commits"
@bjdixon
bjdixon / Replace_partial_string_in_MySQL
Last active August 29, 2015 14:04
Replace one string with another for all rows in a field
UPDATE DBNAME.TableName
SET DBNAME.TableName = REPLACE(DBNAME.TableName.FieldName,'OldString','NewString')
WHERE DBNAME.TableName.FieldName like '%OldString%';
@bjdixon
bjdixon / app.js
Created August 30, 2014 01:38 — forked from tj/app.js
cookie based sessions using express
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 August 29, 2015 14:06
Check if value is an array or not in javascript
// 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 September 21, 2014 20:30
css for using ng-cloak directive
[ng\:cloak], [ng-cloak], [data-ng-cloak], .ng-cloak, .x-ng-cloak {
display: none;
}
@bjdixon
bjdixon / upgrade_node_with_npm
Created January 27, 2015 16:41
Upgrade node version using npm
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
node -v
@bjdixon
bjdixon / jquery.exists
Created April 27, 2015 13:17
Extend jquery with function to check if an element 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 June 3, 2015 00:38
List all events registered to a particular element
$._data( $(selector)[0], "events" );
@bjdixon
bjdixon / combinators.js
Last active August 29, 2015 14:25
Combinators in JavaScript (ES6)
// 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 ) ) ) );