Skip to content

Instantly share code, notes, and snippets.

View nickl-'s full-sized avatar

Nick Lombard nickl-

View GitHub Profile
@nickl-
nickl- / complex.php
Created February 6, 2013 17:01
$ time php complex.php real 3m9.142s user 0m32.125s sys 0m0.358s
<?php
function foo() { return true; }
function bar() { return true; }
function baz() { return false; }
function bat() { return true; }
function lorem() { return true; }
function ipsum() { return true; }
function dolor() { return false; }
function sit() { return false; }
function amet() { return true; }
@nickl-
nickl- / gist:4696036
Last active December 12, 2015 02:08
PHP optimized strtotime() for 24hr time stnings
<?php
/**
* Optimized strtotime function.
* For turning 24hr time in the form HH:MM:SS into its equivalent
* epoch time.
*
* Returns the same result as strtotime but instead of 0m29.337s
* for 1 million records it only takes 0m15.243s or a whopping
* 192% performance boost.
*
@nickl-
nickl- / gist:4584270
Last active December 11, 2015 10:08
simmetrics exampleProgram all
$ ./exampleProgram/exampleProgram all simmetrics symmetrics
Block Distance between simmetrics & symmetrics is 1 and yields a 50% similarity
Cosine Similarity between simmetrics & symmetrics is not applicable and yields a 0% similarity
Dice Similarity between simmetrics & symmetrics is not applicable and yields a 0% similarity
Euclidean Distance between simmetrics & symmetrics is 1.41 and yields a 29% similarity
Jaccard Similarity between simmetrics & symmetrics is not applicable and yields a 0% similarity
Jaro Similarity between simmetrics & symmetrics is not applicable and yields a 87% similarity
Jaro Winkler Similarity between simmetrics & symmetrics is not applicable and yields a 88% similarity
Levenshtein Distance between simmetrics & symmetrics is 1 a
@nickl-
nickl- / gist:4575427
Last active December 11, 2015 08:48
Respect/Foundation new `make phantomjs-inject` to inject javascript into any page right from the shell with `alert()`, `console.log()` and/or `return` values echoed to stdout. Now with verbose target `make phantomjs-inject-verbose` for complete transparency, for those times when you just have to know more about what exactly is going on. Find out…
$ make phantomjs-inject
Respect/Foundation: 0.1.13
Usage: make phantomjs-snapshot url=<site-url> [code=jQuery Script] or use stdin
Example:
As command line argument:
make phantomjs-inject url=respect.li code='alert($$("title").text());'
note: requires dollar escaped as double dollar $$
From stdin:
@nickl-
nickl- / make php.sh
Last active December 10, 2015 22:59
#!/bin/bash
function make_php_ini() {
continue_after 5 "Config ini" && return
if [[ -n "$DEFAULT_INI" ]]; then
if [[ -f "$PREFIX/$DEFAULT_INI" ]]; then
cp "$PREFIX/$DEFAULT_INI" "$PREFIX/etc/php.ini"
else
if [[ -f "$DEFAULT_INI" ]]; then
@nickl-
nickl- / gist:4496194
Created January 9, 2013 19:44
Headless webkit on a stick
$ echo '$("a").each(function () {
alert($(this).text());
});'|make phantomjs-inject url=google.co.za
Respect/Foundation: 0.1.12
http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js
+You
Search
Images
Maps
@nickl-
nickl- / gist:4365985
Created December 23, 2012 20:45
interface-schema
{
"extends":"http://json-schema.org/hyper-schema",
"description":"A schema for schema interface definitions that describe programmatic class structures using JSON schema syntax",
"properties":{
"methods":{
"type":"object",
"description":"This defines the set of methods available to the class instances",
"additionalProperties":{
"type":"object",
"description":"The definition of the method",
@nickl-
nickl- / gist:4365978
Created December 23, 2012 20:44
json-ref-schema
{
"$schema": "http://json-schema.org/draft-03/hyper-schema#",
"id": "http://json-schema.org/draft-03/json-ref#",
"additionalItems": { "$ref": "#" },
"additionalProperties": { "$ref": "#" },
"links": [
{
"href": "{id}",
"rel": "self"
},
@nickl-
nickl- / gist:4365949
Created December 23, 2012 20:41
hypermedia-links-schema
{
"$schema": "http://json-schema.org/draft-03/hyper-schema#",
"id": "http://json-schema.org/draft-03/links#",
"type": "object",
"properties": {
"href": {
"type": "string",
"required": true
},
@nickl-
nickl- / gist:4365944
Created December 23, 2012 20:40
hypermedia-schema
{
"$schema": "http://json-schema.org/draft-03/hyper-schema#",
"id": "http://json-schema.org/draft-03/hyper-schema#",
"extends": { "$ref": "http://json-schema.org/draft-03/schema#" },
"properties": {
"links": {
"type": "array",
"items": { "$ref": "http://json-schema.org/draft-03/links#" }
},
"fragmentResolution": {