Skip to content

Instantly share code, notes, and snippets.

@bign8
bign8 / README.md
Last active April 1, 2018 12:35 — forked from ncr/README
jQuery plugin to allow single and double click handlers on an element

Code

$("button").single_double_click(function () {
  alert("Try double-clicking me!")
}, function () {
  alert("Double click detected, I'm hiding")
  $(this).hide()
})
@bign8
bign8 / config_sample.php
Last active August 29, 2015 13:56
An abstraction of PHP's PDO.
<?php
class config {
// For PHPMailer Class for sending email from forms and error reports
const defaultEmail = '';
const defaultFrom = '';
const notifyEmail = '';
const notifyName = '';
// For database connection scheme
@bign8
bign8 / mysql2sqlite.sh
Last active December 13, 2022 09:30 — forked from esperlu/mysql2sqlite.sh
Combining many of the forks to build a simple script that works
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is chosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@bign8
bign8 / interpolatef.php
Last active August 29, 2015 13:56
Formatted Interpolate for PHP
<?php
/*
name: formatted interpolate (see: http://bit.ly/198oCOP on interpolation)
author: bign8
description: using the format "{key|format}", interpolatef does formatted interpolation of strings using sprintf formatting
*/
function interpolatef( $message, array $context = array()) {
$callback = function ($matches) use ($context) { // function that formats data as specified
$format = $matches[2] == '' ? '%s' : $matches[2] ; // default format
return (isset($context[$matches[1]])) ? sprintf($format, $context[$matches[1]]) : $matches[0];
@bign8
bign8 / pagination.js
Last active August 29, 2015 13:57
Angular Pagination Stuff
angular.module('app', []).
controller('ctrl', ['$scope', function ($scope) {
$scope.pages = function () {
return Math.ceil( $scope.filtered_users.length / $scope.limit ) || 1;
};
}]).
filter('pagination', function () {
return function (inputArray, selectedPage, pageSize) {
@bign8
bign8 / sample.js
Created March 28, 2014 16:33
Image Pre-loader
// Note: pre-fetching all images is dumb! It wastes bandwidth on content that "might" be viewed
// Instead: Look up something called "Lazy Loading"
(function (queue, mapper) {
mapper = mapper || function (obj) { return obj; };
var image = new Image(), index = 0;
image.onload = function () {
if (index < queue.length) image.src = mapper( queue[index++] );
};
image.onerror = function (e) {
@bign8
bign8 / links.js
Last active August 29, 2015 14:01
@bign8
bign8 / example.js
Last active August 29, 2015 14:01
Angular.js and TinyMCE playing nicely (in dialogs too)
// A sample MCE_OBJ that can load on everything, then clean itself up for the directive above.
var MCE_OBJ = {
selector: 'textarea',
menubar: false,
toolbar_items_size: 'small',
plugins: 'link image code',
toolbar: "undo redo | styleselect | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image code",
setup: function (editor) { // cleanup for angular
delete MCE_OBJ.selector;
@bign8
bign8 / gravatar-proxy-use.js
Created May 27, 2014 04:14
Gravatar Proxy with Node.js
var app = require('express')(),
gravatar_proxy = require('./gravatar-proxy.js');
app.all('/gravatar/:hash', gravatar_proxy()); // http://localhost/gravatar/example@example.com
@bign8
bign8 / form.php
Created July 16, 2014 02:33
Mailer.php
<?php session_start(); $_SESSION['hash'] = uniqid(); ?>
<!-- ... -->
<form method="post" action="/mail.php">
<input type="hidden" name="hash" value="<?php echo $_SESSION['hash']; ?>" />
<!-- ... -->