Skip to content

Instantly share code, notes, and snippets.

View ianchanning's full-sized avatar

Ian Channing ianchanning

View GitHub Profile
@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

This is my attempt at converting a solution to a pascal's triangle problem that I'd written in an imperitive manner into a functional one. I kind of hope that anyone reading this is also trying to figure out the meanings behind functional programming, I'm trying to describe all the steps that I go through.

It is a mini way of me trying to discover what being 'declarative' actually means.

I know the kind of definition e.g.:

  1. "say what you want" not "how to do it"
  2. picture vs recipie
  3. sqrt(2) vs looping from x = 1 finding the mean of x and 2/x
  4. SQL, Haskell vs C++, Java
@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%

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 / readme.md
Last active September 8, 2019 07:16
What are the differences between segment trees, interval trees, binary indexed trees and range trees?
@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
(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-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 / !.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