Skip to content

Instantly share code, notes, and snippets.

View ianchanning's full-sized avatar

Ian Channing ianchanning

View GitHub Profile
@ianchanning
ianchanning / ping.php
Created June 14, 2013 17:17
PHP Ping Packets
<?php
/**
* Ping a host using an IMCP packet
*
* N.B. This function must be called by an administrator / root user as socket_create requires this
*
* @param string $host domain
* @param integer $timeout seconds
* @return mixed False | Response time milliseconds
*
@ianchanning
ianchanning / monad.md
Last active March 12, 2018 08:50
Yet another monad explanation

tl;dr Here's a really short explanation for JavaScript, as in just the flatmap part.

map is pretty well understood in JavaScript (and I'm assuming you understand it).

So you 'just' need to make the leap to flatmap. Which is mapping something and flattening the result.

Flattening a JavaScript array is concatenating a 2D array into an array.

Longer Python example

Another attempt at explaining monads, using just Python lists and the map function. I fully accept this isn't a full explanation, but I hope it gets at the core concepts.

@ianchanning
ianchanning / datatables.json
Created May 17, 2017 14:00
Data Tables JSON
{
"data": [
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
@ianchanning
ianchanning / .vimrc
Last active April 24, 2017 15:25
.vimrc hacks
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer:
" Amir Salihefendic
" http://amix.dk - amix@amix.dk
"
" Version:
" 5.0 - 29/05/12 15:43:36
"
" Blog_post:
@ianchanning
ianchanning / sublimetext-to-vim-translation.md
Last active April 23, 2017 13:40
Translating Sublime Text into Vim

Translating Sublime Text into Vim

Intro

Coming from a Windows world getting into Vim, to me is almost exactly like the struggles I had learning French or Dutch. I spent 10 years learning French growing up and I can't speak a proper sentence. I then moved from England to the Dutch speaking part of Belgium (Flanders) and I learnt to speak Dutch to a conversational level within 2 years.

If you're going to learn Vim you need to immerse yourself in it. I suspect the majority of Vim users only ever use it to make minor file modifications via SSH. That's what I did anyway.

I've used lots of editors in Windows but the one I prefer now is [Sublime Text][2] (ST). However ST has almost all the exact same commands as other editors, with the one major improvement which is Ctrl+P, we'll come to that later. ST is free to use with a popup once in a while, its a great tool, you should buy a licence.

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 / !.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 / casper-google-disco-v2.js
Last active May 16, 2016 09:15
Bowie discography scraping
var links = [];
var casper = require('casper').create();
function getLinks() {
var links = document.querySelectorAll('div#mw-content-text table.wikitable tbody tr td i b a');
return Array.prototype.map.call(links, function(e) {
return 'https://en.wikipedia.org' + e.getAttribute('href');
});
}
@ianchanning
ianchanning / wp-bcrypt.php
Last active May 11, 2016 13:34
internationalized version of wp-bcrypt
<?php
/**
* Plugin Name: wp-bcrypt
* Plugin URI: http://wordpress.org/plugins/wp-bcrypt/
* Description: wp-bcrypt switches WordPress's password hashes from MD5 to bcrypt, making it harder for them to be brute-forced if they are leaked.
* Author: dxw
* Author URI: http://dxw.com
* Version: 1.0.2
* Licence: GPL2
*
//-------------------------------------------------------------------
// Copyright (c) 2011, Jeff Preshing
// http://preshing.com/20110811/xkcd-password-generator
// All rights reserved.
//
// Some parts based on http://www.mytsoftware.com/dailyproject/PassGen/entropy.js, copyright 2003 David Finch.
//
// Released under the Modified BSD License:
//
// Redistribution and use in source and binary forms, with or without