Skip to content

Instantly share code, notes, and snippets.

@aanton
aanton / timezones.php
Created April 4, 2014 07:46
Test timezones in PHP
<?php
$serverTimezone = 'Europe/Madrid';
$timezones = ['America/Los_Angeles', 'America/Mexico_City', 'Atlantic/Canary', 'Europe/Madrid'];
$tmst = time();
$datetimeNow = new DateTime('now', new DateTimeZone($serverTimezone));
$datetimes = array();
foreach ($timezones as $timezone)
@aanton
aanton / ConsistentHash.php
Created April 4, 2014 07:47
Consistent hashing
<?php
/**
* @see https://github.com/pda/flexihash
* @see http://www.martinbroadhurst.com/Consistent-Hash-Ring.html
*/
class ConsistentHash
{
/** @var int Number of positions to hash each target. This has the effect of distributing the servers more evenly over the ring. Note that this has nothing to do with server replication */
private $replicas;
@aanton
aanton / memcache-list-all-keys.rb
Last active August 29, 2015 14:13 — forked from bkimble/gist:1365005
List all keys stored in memcache
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
# Forked from https://gist.github.com/bkimble/1365005
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
@aanton
aanton / debug-charsets-requests.php
Created September 24, 2015 20:48
PHP example to debug requests done in ISO-8859-1 & UTF-8 pages
<?php
$debug = [];
// Configure charset
$charsets = ['utf-8', 'iso-8859-1'];
$charset = array_key_exists('charset', $_REQUEST) &&
in_array(mb_strtolower($_REQUEST['charset']), $charsets) ? mb_strtolower($_REQUEST['charset']) : 'utf-8';
ini_set('default_charset', $charset);
mb_internal_encoding(ini_get('default_charset'));
@aanton
aanton / 10gen-extract-videos.js
Created June 19, 2013 08:43
Get all videos URLs of a week in a course from education.10gen.com using web scrapping, javascript, jquery and browser console
/*
Instructions:
1. Log in with your account and go to the desired course
2. Open the courseware tab
3. Configure the week variable
4. Copy this code and paste it in the browser console
*/
@aanton
aanton / Responsive-layout.markdown
Created October 10, 2013 12:57
A Pen by Armando Anton.
@aanton
aanton / Null.php
Created November 25, 2013 07:26
Null PHP Class
<?php
class Null
{
private static $instance;
public function __call($name, $arguments)
{
if (strpos($name, 'is') === 0 || strpos($name, 'has') === 0)
{
@aanton
aanton / .gitconfig
Created February 16, 2016 10:26
My .gitconfig
[core]
editor = vim
pager = less -r
[alias]
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --all --date=iso
local = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=iso
[color]
ui = auto
[color "branch"]
current = yellow reverse

Keybase proof

I hereby claim:

  • I am aanton on github.
  • I am aanton (https://keybase.io/aanton) on keybase.
  • I have a public key ASDy6XVLDZ6WeKCLIJPiQziwfLE1D9XsZqlZxLtyjkMcmgo

To claim this, I am signing this object:

@aanton
aanton / atom-update.sh
Last active September 1, 2016 07:00
Atom auto-update script for Debian/Ubuntu Linux
#!/bin/bash
if [ $EUID != 0 ]; then
echo "You must be root to run this script" 1>&2
exit 1
fi
URL_RELEASES="https://github.com/atom/atom/releases/latest"
NEW_RELEASE=$(curl -sL $URL_RELEASES | egrep -o 'href="([^"#]+)atom-amd64.deb"' | cut -d'"' -f2 | sort | uniq)
NEW_VERSION=$(echo $NEW_RELEASE | egrep -o '[0-9]+\.[0-9]+\.[0-9]+')
CURRENT_VERSION=$(atom --version | fgrep Atom | awk '{print $3}')