Skip to content

Instantly share code, notes, and snippets.

View ianchanning's full-sized avatar

Ian Channing ianchanning

View GitHub Profile
function login($username, $password) {
$options = array('cost' => 10);
$userdata = 'query to find the user in your framework/PDO prepared query';
$plainText = $password;
if ($userdata['legacy']) {
$password = md5($password);
}
@ianchanning
ianchanning / jquery-chker.htm
Last active May 8, 2016 07:51
jQuery timer function
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>chker</title>
<link type="text/css" href="style.css" rel="stylesheet" />
</head>
<body>
<div id="chker" class="chker">
@ianchanning
ianchanning / BifurDiag.m
Last active April 6, 2016 01:49
A Matlab program to iterate the logistic map - Dana Kester (with slight modifications by me)
% http://www.po.gso.uri.edu/tracking/tracking/chaos/presentations/bifurcationmicroscope/
%BifurDiag.m is a Matlab program to construct a bifurcation diagram for the logistic map
%to allow exploring the period doubling route to Chaos. Dana Kester, Oct. 2002
% The logistic map is x[t+1] = r*x[t]*(1-x[t]) where 0 < r < 4 is a parameter
% value and 0 < x[t] < 1 is a variable. The user specifies the following:
% rmin = the lowest value of r to three decimals (or maybe two decimals)
% rmax = the highest value of r to three decimals (or maybe two decimals)
% xo = initial value of x[t]
% num = number of iterations

Segment Trees

Wow they seem overly complex to learn about. They're a very easy concept, but there is a paucity of resources for explaining them.

Have a gander at the resources at the bottom for the ones I came across. Took me ages to figure out the differences between them.

Here, I assume you know about Binary Trees and recursion on Binary Trees.

Any code is in python which is about as close to pseudo code as you can get.

@ianchanning
ianchanning / doskey-shortcut.bat
Created February 3, 2016 16:41
Shortcut target to save command history to history.log
%windir%\system32\cmd.exe /K doskey exit=doskey/history$g$g%USERPROFILE%\history.log$texit $1 $2
@ianchanning
ianchanning / doskey.bat
Last active February 3, 2016 16:38
Dos command history
doskey /history >> %USERPROFILE%\history.txt%
@ianchanning
ianchanning / svn_upgrade_wordpress.sh
Last active December 24, 2015 13:49
For upgrading WordPress when you've got a subversion installation. Backs up the database then upgrades WordPress to the specified version. A bit odd having subversion commands on github... but hey.
#!/bin/bash
# usage: svn_upgrade_wordpress.sh X.X.X
# http://codex.wordpress.org/Installing/Updating_WordPress_with_Subversion
# licence MIT
die () {
echo >&2 "$@"
exit 1
}
(function($) {
jQuery.fn.chker = function() {
var timer = $(this);
var timerId = 0;
var tickInterval = 1000;
var dd = timer.find('.day');
var hh = timer.find('.hr');
var mm = timer.find('.min');
var ss = timer.find('.sec');
@ianchanning
ianchanning / jquery.chk.js
Last active October 13, 2015 12:18
A general object for ticking a set of values up or down
(function($) {
/**
* A general object for ticking a set of values up or down
*
* Each tick is done on a unit (e.g. hour / minute / second)
* And compared against all the fractions of the unit e.g. seconds are fractions of a minte
* Short for chained tick I think of it as 'chuck' rather than 'check', i.e. 'chuck up'
* Also see: @link https://en.wikipedia.org/wiki/!!!
*
* This code was based off https://github.com/kellishaver/stopwatch but pretty much all that is left of that are the zeroPad and hand functions
@ianchanning
ianchanning / extract-wp-config-db.sh
Created October 21, 2014 13:56
Sed commands to pull out wp-config database constants
# taken from jplew's excellent SyncDB
# @link https://github.com/jplew/SyncDB/blob/master/syncdb
all_db_name=$(sed -n "s/.*DB_NAME', '\([^']*\)'.*/\1/p" wp-config.php)
all_db_user=$(sed -n "s/.*DB_USER', '\([^']*\)'.*/\1/p" wp-config.php)
all_db_pass=$(sed -n "s/.*DB_PASSWORD', '\([^']*\)'.*/\1/p" wp-config.php)
all_db_host=$(sed -n "s/.*DB_HOST', '\([^']*\)'.*/\1/p" wp-config.php)