Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
dhrrgn / benchmark.php
Last active August 29, 2015 14:00
Handy Benchmarking Function
<?php
function benchmark($name, $iterations, Closure $function)
{
echo "Starting Benchmark: {$name} (".number_format($iterations)." Iterations)\n";
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$function();
}
$elapsed = microtime(true) - $start;
@kelvinn
kelvinn / new-do-db.yml
Last active August 29, 2015 14:03
Creating Digital Ocean Droplets with unique names using Ansible
---
- name: Prepare New Digital Ocean Droplet
hosts: you.example.com
user: ansible
tasks:
- action: shell date +%s | sha256sum | base64 | head -c 6
register: rand_var
- digital_ocean: >
state=present
command=droplet
@dhrrgn
dhrrgn / MySQLiProxy.php
Created August 15, 2014 15:28
A MySQLi Proxy with Query logging.
<?php
namespace Core\Database;
use Logger;
use mysqli;
use Psr\Log\LoggerInterface;
/**
* Class MySQLiProxy
(function () {
var root = $(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
if (element.data().hasOwnProperty('$scope')) {
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
watchers.push(watcher);
});
}
---
- name: Install libfontconfig1
apt: pkg=libfontconfig1 state=installed
- name: Download phantomjs
get_url: url=https://bitbucket.org/ariya/phantomjs/downloads/{{phantomjs.name}}.tar.bz2 dest=/usr/local/share/{{phantomjs.name}}.tar.bz2 validate_certs=no
- name: Unpack phantomjs
command: tar xvjf /usr/local/share/{{phantomjs.name}}.tar.bz2 -C /usr/local/share creates=/usr/local/share/{{phantomjs.name}}
@mathiasverraes
mathiasverraes / max.php
Created December 9, 2014 19:40
max($list, $function) in php
<?php
// test data
class Foo {
private $a;
private $b;
function __construct($a, $b)
{
#!/bin/bash
# Script for placing sudoers.d files with syntax-checking
# Making a temporary file to contain the sudoers-changes to be pre-checked
TMP=$(mktemp -t vagrant_sudoers)
cat /etc/sudoers > $TMP
cat >> $TMP <<EOF
# Allow passwordless startup of Vagrant when using NFS.
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/su root -c echo '*' >> /etc/exports
@robhurring
robhurring / renderer.php
Created March 29, 2010 17:40
PHP Template Rendering
<?php
class MissingTemplateException extends Exception {}
function render_template($template_file, $vars = array())
{
if(file_exists($template_file))
{
ob_start();
extract($vars);
include($template_file);
@JeanSebTr
JeanSebTr / session.class.php
Created December 6, 2011 00:24
Exemple de class pour gérer les Session sans le mécanisme de session PHP.
<?php
/**
* Author : Jean-Sébastien Tremblay <jean-seb@total-itech.com>
* Description : Class for scalable, stateless and client-side sessions
*/
/* Usage :
generate IV :
// do this only on time and save in config
@mhayes
mhayes / changed.js
Created August 10, 2012 18:30
Foundation Custom Forms
// When something changes
$("#changedSelectInput").foundationCustomForms();