Skip to content

Instantly share code, notes, and snippets.

@drm
drm / gist:1087457
Created July 17, 2011 11:00
Automate nano sudo
function nano() {
nano=`which nano`;
if ([ -e "$1" ] && ! [ -w "$1" ]) || ( ! [ -e "$1" ] && ! [ -w "`dirname $1`" ]); then
read -n 1 -p "$1 is not editable by you. sudo [y/N]? " y
[ "$y" == "y" ] || [ "$y" == "Y" ] && echo -e "\n" && sudo $nano $@
else
$nano $@
fi
}
@drm
drm / hide_cursor.php
Created January 27, 2012 10:50
Hide the cursor in a PHP script with ANSI escape code
<?php
function hide_cursor($stream = STDOUT) {
fprintf($stream, "\033[?25l"); // hide cursor
register_shutdown_function(function() use($stream) {
fprintf($stream, "\033[?25h"); //show cursor
});
}
@drm
drm / cprintf.php
Created January 27, 2012 10:52
ANSI colorized output
<?php
/**
* Write colorized text to a stream
*
* @param $stream
* @param $text
* @param $args
*/
function cprintf($stream, $text, $args = null) {
@drm
drm / FooBuilderTest.php
Created May 13, 2012 17:21
Example using closures as data provider in PHPUnit
<?php
/**
* @author Gerard van Helden <drm@melp.nl>
*/
class FooBuilder {
protected $properties = array();
function add($property, $value) {
$this->properties[$property][] = $value;
@drm
drm / jetty-logging.xml
Created May 29, 2012 09:26
Jetty logging configuration
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<!-- =============================================================== -->
<!-- Configure stderr and stdout to a Jetty rollover log file -->
<!-- this configuration file should be used in combination with -->
<!-- other configuration files. e.g. -->
<!-- java -jar start.jar etc/jetty-logging.xml etc/jetty.xml -->
<!-- =============================================================== -->
<Configure id="Server" class="org.mortbay.jetty.Server">
@drm
drm / moochallenge-1.html
Created August 16, 2012 22:37
Moo tools challenge #1
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="author" content="Gerard van Helden <drm@melp.nl>">
<style type="text/css">
div#container {
position: relative;
}
@drm
drm / gist:3871428
Created October 11, 2012 10:14
bash: split args & opts
#!/usr/bin/env bash
function a {
echo "let's do A!"
}
function b {
echo "Let's do B!"
}
@drm
drm / gist:4158455
Created November 28, 2012 01:29
tetris.html
<!doctype html>
<html>
<body>
<pre id="canvas" style="font-size:20px; font-weight:bold;"></pre>
</body>
</html>
<script type="text/javascript">
<?php
/**
* @author Gerard van Helden <gerard@zicht.nl>
* @copyright Zicht Online <http://zicht.nl>
*/
require_once 'vendor/autoload.php';
class MyConf implements \Symfony\Component\Config\Definition\ConfigurationInterface
{
<?php
/**
* @author Gerard van Helden <gerard@zicht.nl>
* @copyright Zicht Online <http://zicht.nl>
*/
require_once 'vendor/autoload.php';
class MyConf implements \Symfony\Component\Config\Definition\ConfigurationInterface
{