Skip to content

Instantly share code, notes, and snippets.

View billymoon's full-sized avatar

Billy Moon billymoon

View GitHub Profile
@billymoon
billymoon / jquery-hook-issues
Created September 16, 2011 17:00
explaining problems with jQUery hooks
$.hook = function (fns){
fns = typeof fns === 'string' ? fns.split(' ') : $.makeArray(fns);
jQuery.each( fns, function (i, method) {
var old = $.fn[ method ];
if( old && !old.__hookold ){
$.fn[ method ] = function(){
this.triggerHandler('onbefore'+method);
this.triggerHandler('on'+method);
var ret = old.apply(this, arguments);
this.triggerHandler('onafter'+method);
@billymoon
billymoon / php-auth-linux-account.php
Created October 30, 2011 10:34
function to authenticate users from within php against linux user accounts on the server
/* Need to add www-data to group shadow (and restart apache)
$ sudo adduser www-data shadow
$ sudo /etc/init.d/apache2 restart
Needs whois to be installed to run mkpasswd
$ sudo apt-get install whois
Assumes that sha-512 is used in shadow file
*/
function authenticate($user, $pass){
// run shell command to output shadow file, and extract line for $user
CREATE TABLE IF NOT EXISTS `purchases` (`Purchase_ID` int(11), `Datetime` datetime, `Reward_ID` int(11), `Quantity` int(11), `Student_ID` int(11), `Student_Name` varchar(100), `Date_DealtWith` datetime, `Date_Collected` datetime);
DELETE FROM `purchases`;
INSERT INTO `purchases` (`Purchase_ID`, `Datetime`, `Reward_ID`, `Quantity`, `Student_ID`, `Student_Name`, `Date_DealtWith`, `Date_Collected`) VALUES
(1, '2011-09-27 16:55:16', 1, 1, 34240, '', '2011-09-27 16:55:16', '2011-12-12 15:45:43'),
(2, '2011-09-28 13:02:26', 1, 1, 137636, '', '2011-09-27 16:55:16', '2011-09-27 16:55:16'),
(3, '2011-09-29 11:29:09', 1, 1, 137685, '', NULL, NULL),
(4, '2011-09-29 11:29:09', 1, 1, 928734, '', NULL, NULL);
@billymoon
billymoon / fiddle.js
Created August 10, 2012 01:07
Manipulate the content of HTML strings without changing the HTML
/**
* Manipulate text inside HTML according to passed function
* @param html the html string to manipulate
* @param manipulator the funciton to manipulate with (will be passed single word)
* @returns manipulated string including unmodified HTML
*
* Currently limited in that manipulator operates on words determined by regex
* word boundaries, and must return same length manipulated word
*
*/
var module = {
exports : {}
}
YUI.add('dlp-jquery-commonjs', function(Y) {
function getFile(url) {
if (window.XMLHttpRequest) {
AJAX=new XMLHttpRequest();
} else {
@billymoon
billymoon / Dream-Team.markdown
Last active October 31, 2015 14:49
A Pen by Billy Moon.
@billymoon
billymoon / ux-logo.svg
Created July 29, 2014 23:46
Alternative variation of UX logo for ux.stackexchange.com
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@billymoon
billymoon / file1.txt
Last active October 31, 2015 14:42
there were 0.17658892646431923 green bottles
there were 0.6299692264292389 green bottles..!
@billymoon
billymoon / wordwrap
Created December 30, 2015 19:56
near identical implementation of wordwrap from php.js
// slight discrepency with...
// var str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias veritatis, quis sunt cumque quod, dolorum! Itaque, inventore, sed. Nisi natus illum minima architecto, reprehenderit fugiat repellendus doloremque dolore adipisci aspernatur? suscipit, esse delectus tempora dolor aliquam excepturi, tempore non mollitia eum dolorem quidem eius quasi est, explicabo eos doloremque. Impedit! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo, dolores, perferendis. At perferendis porro quidem in praesentium quia fuga nihil fugiat ratione. Provident, minima labore blanditiis mollitia sit voluptatibus quod.";
// wordwrap(str, 60, '\n', 2);
// but pretty close to functionally equavalent.
function wordwrap(str, intWidth, strBreak, cut) {
intWidth = typeof intWidth !== 'undefined' ? intWidth : 75;
strBreak = typeof strBreak !== 'undefined' ? strBreak : '\n';
cut = typeof cut !== 'undefined' ? cut : 0;
@billymoon
billymoon / functional-pollyfills.carbide.md
Last active October 2, 2016 22:13
functional-pollyfills

functional-pollyfills