Skip to content

Instantly share code, notes, and snippets.

View ianchanning's full-sized avatar

Ian Channing ianchanning

View GitHub Profile
@ianchanning
ianchanning / dismiss.js
Last active August 29, 2015 14:07
Pure javascript dismissable divs that stay dismissed when you dismiss them
/**
* Dismissable divs that stay dismissed when you dismiss them
*
* Besides the dismiss/check its also a generic Cookie monster
*
* The cookie code is intially from the uk-cookie-consent plugin
* @link https://wordpress.org/plugins/uk-cookie-consent/
*
* Make the js less obtrusive
* @link http://www.w3.org/wiki/The_principles_of_unobtrusive_JavaScript
@ianchanning
ianchanning / wordpress_migrate.sh
Last active August 29, 2015 14:07
Migrate a WordPress sql script from one domain to another
#!/bin/bash
# mysqldump your product database to database_name_here.sql
# transfer it to this file's directory on another server
# copy wordpres_migrate.yml to this file's directory and update the variables
# usage: wordpress_migrate.sh [config.yml]
die () {
echo >&2 "$@"
exit 1
}
@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)
@ianchanning
ianchanning / !.bat
Last active December 26, 2016 13:14
Basic windows history and bang commands (assuming Git installed)
@echo off
rem simple replacement for linux ! syntax e.g. !591
rem usage: ! N (executes line N of history.log)
rem @link http://ianchanning.wordpress.com/2014/10/29/dos-command-history/
if "%1"=="" goto Syntax
if "%1"=="/?" goto Syntax
for /f "tokens=*" %%x in ('sed -n "%1{p;q}" %USERPROFILE%\history.log') do echo %%x & cmd /c %%x
goto End
@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">
(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 / readme.md
Last active September 8, 2019 07:16
What are the differences between segment trees, interval trees, binary indexed trees and range trees?

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.bat
Last active February 3, 2016 16:38
Dos command history
doskey /history >> %USERPROFILE%\history.txt%