Skip to content

Instantly share code, notes, and snippets.

💻
Working on league/commonmark 2.0!

Colin O'Dell colinodell

💻
Working on league/commonmark 2.0!
View GitHub Profile
@colinodell
colinodell / checker.php
Created Oct 24, 2014
Google Inbox invite checker
View checker.php
<?php
$last = '';
while (true) {
$json = file_get_contents('https://www.reddit.com/r/google/comments/2k0kjr/google_inbox_invite_chain.json?sort=new&foo='.rand(1,500));
$json = json_decode($json, true);
$comment = $json[1]['data']['children'][0];
$msg = $comment['data']['author'] . ' - ' . $comment['data']['body'] . "\n";
if ($msg != $last) {
View keybase.md

Keybase proof

I hereby claim:

  • I am colinodell on github.
  • I am colinodell (https://keybase.io/colinodell) on keybase.
  • I have a public key whose fingerprint is 8FBC 987A 0483 128A C055 E483 60A4 DAD2 72A0 1CB8

To claim this, I am signing this object:

View console.js
// Super-simple console script to push the button only when the timer gets low
var h;
var armed = false;
var lowestSoFar = 9999999999;
h = setInterval(function() {
if (r.thebutton._msLeft <= 0) {
console.log('Game over :-/');
clearInterval(h);
return;
View rateLimit.js
// Returns a function that won't fire more than
// once every `wait` milliseconds.
//
// Example usage:
//
// $('.button').click(rateLimit(function(){
// console.log('clicked!');
// }));
//
function rateLimit(func, wait) {
@colinodell
colinodell / AbstractEnum.php
Created Aug 18, 2015
Enum-like class for PHP
View AbstractEnum.php
<?php
/**
* Base class used to build enums
*/
abstract class AbstractEnum
{
/**
* @var array Options array, suitable for a select box
*/
@colinodell
colinodell / create-multiple.sh
Created Aug 20, 2015
Create Drupal upgrade patches
View create-multiple.sh
#!/bin/bash
# A sample script for batch-creating multiple patches at once
# Generate 6.x patches
for i in `seq 0 36`
do
./create-patch.sh 6.$i 6.37
done
# Generate 7.x patches
@colinodell
colinodell / services.yml
Created Aug 20, 2015
Guzzle with logger
View services.yml
services:
guzzle.client:
class: Guzzle\Http\Client
calls:
- [addSubscriber, ["@guzzle.logger"]]
guzzle.logger:
class: Guzzle\Log\MonologLogAdapter
arguments:
- "@logger"
@colinodell
colinodell / ParagraphDirProcessor.php
Created Mar 10, 2016
Adding 'dir' attribute to all paragraphs (UNTESTED)
View ParagraphDirProcessor.php
<?php
// TODO: Set your "namespace" and "use" statements here
// Also see this documentation: http://commonmark.thephpleague.com/customization/abstract-syntax-tree/#document-processor
class ParagraphDirProcessor implements DocumentProcessorInterface
{
public function processDocument(Document $document)
{
$walker = $document->walker();
@colinodell
colinodell / _description.md
Last active May 28, 2016
array_change_keys()
View _description.md

Problem

AFAIK, there are no core PHP methods which allow you to re-key an array.

Okay, that's not entirely true - there is array_change_key_case(), but whenever I need to change an array's keys it's never been this use case.

You could do it with a foreach loop:

$newArray = [];
@colinodell
colinodell / benchmark.php
Created May 30, 2016
array_change_keys() benchmark
View benchmark.php
<?php
$a = range(1, 10000000);
echo "Test 1 - Using foreach\n";
$start = microtime(true);
$b = [];
foreach ($a as $k => $v) {
$b[md5($v)] = $v;
You can’t perform that action at this time.