Skip to content

Instantly share code, notes, and snippets.

@mbjordan
mbjordan / partial.js
Last active September 26, 2015 21:01
function partial(fn) { // `fn` is the original function
// `args_a` are the arguments (barring `fn`) of the first call.
var args_a = Array.prototype.slice.call(arguments, 1);
// Now, we return a new function, with the first set of arguments already applied.
return function partialApplicator() {
// `args_b` are the arguments applied at the second call
var args_b = Array.prototype.slice.call(arguments);
// Now, concatenate both Arrays and apply them to the original function
@mbjordan
mbjordan / format-number.js
Created January 10, 2012 20:41
Format a number with commas in JavaScript
function number_format(n) {
n += '';
x = n.split('.');
y = x[0];
z = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(y)) {
y = y.replace(rgx, '$1' + ',' + '$2');
}
return y + z;
@mbjordan
mbjordan / jQuery.mintip.js
Created January 12, 2012 03:03 — forked from FND/jQuery.mintip.js
jQuery MinTip: minimal tooltips
/*jslint vars: true, unparam: true, browser: true, white: true */
/*global jQuery */
(function ($) {
"use strict";
var onEnter, onLeave, startTimer, stopTimer, remove, getPos;
var defaults = {
delay: 500,
content: null,
allowHTML: false // XXX: rename
};
@mbjordan
mbjordan / jquery.copylink.js
Created February 7, 2012 13:08
Simple jQuery function that changes an <a> element to an <input> for copying the href contents.
@mbjordan
mbjordan / texterize.php
Created March 3, 2012 16:40
Strip down and optimize a string for the Google Web Fonts "text" parameter.
<?php
function texterize($s = '') {
$s = str_replace(' ', '', $s);
$s = str_split($s);
$s = array_unique($s);
natcasesort($s);
return urlencode(implode($s));
}
@mbjordan
mbjordan / next-last.sql
Created June 7, 2012 12:05
Get the next and last rows from SQL
-- The comparison "_CURRENT-ID_" is an integer.
--Last Row:
SELECT `field1`
FROM `tablename`
WHERE `id` < '_CURRENT-ID_'
ORDER BY `id` DESC
LIMIT 1
@mbjordan
mbjordan / Bcrypt.php
Created June 7, 2012 12:02
PHP Bcrypt functions
<?php
/*
BCRYPT function group
*/
function bcrypt_hash($password, $work_factor = 8) {
if ($work_factor < 4 || $work_factor > 31) $work_factor = 8;
$salt = '$2a$'.str_pad($work_factor, 2, '0', STR_PAD_LEFT).'$'.
substr(
@mbjordan
mbjordan / styleNumber.js
Created November 13, 2012 19:42
Style a number
function styleNumber(number, precision) {
if (number.toString().length >= 4) {
var place = 1;
if (precision !== undefined && precision === 1) {
place = 10;
} else if (precision === 2) {
place = 100;
}
number = ((number / 100) / 10) * place;
number = Math.round(number) / place + ' k';
@mbjordan
mbjordan / ref-mask.php
Created November 19, 2012 13:06
HTTP Referral Masking
<?php
session_start();
/**
Setp 1. Get the query string variable and set it in a session, then remove it from the URL.
*/
if (isset($_GET['to']) && !isset($_SESSION['to'])) {
$_SESSION['to'] = urldecode($_GET['to']);
header('Location: http://yoursite.com/path/to/ref-mask.php');// Must be THIS script
exit();
@mbjordan
mbjordan / broncos-blue.txt
Last active October 13, 2015 06:37
Broncos Web Colors
#001F52