Skip to content

Instantly share code, notes, and snippets.

@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 / 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']; ?>" />
<!-- ... -->
@bign8
bign8 / timeout.js
Last active August 29, 2015 14:05
Timeout redirect (js)
! function(t, i, m, e, r, s) {
var a = t.getElementById(i),
c = function() {
a.innerHTML = r, t.location = e
},
d = function() {
a.innerHTML = s.replace('{x}', m).replace('{s}', 1 == m-- ? '' : 's');
setTimeout(0 >= m ? c : d, 1e3)
};
t.addEventListener('DOMContentLoaded', d);
@bign8
bign8 / .gitignore
Last active August 29, 2015 14:19
CSCI-532 Huffman Codes Project
iliad.txt
tables.py
flashplayer.dmg