Skip to content

Instantly share code, notes, and snippets.

<?php
/** Prepare a string for use with wordwrap by hyphenate words longer that $width
*
* Example:
* echo prep("1 12 123 1234 12345 123456 1234567 12345678", 4), PHP_EOL;
* Outputs:
* 1 12 123 123-4 123-45 123-456 123-4567 123-456-78
* XXX: DO NOT USE THIS UNLESS YOU KNOW YOU CAN(See for example preg_quote()).
*/
function prep($str, $width=72) {
#!/bin/bash
function a {
return "/$1"
}
function b {
print $1
}
b $(a "some_file")
@danielholmstrom
danielholmstrom / gist:5336594
Created April 8, 2013 12:55
Nose plugin for excluding files based on python version and filename
from nose.plugins import Plugin
class PyVersion(Plugin):
"""Nose plugin that excludes files based on python version and file name
If a filename has the format NAME.pyVERSION.py and VERSION doesn't match
[major][minor][micro], [major][minor] or [major] the file will be excluded
from tests.
if (true) {
function declaration() {
return "first";
}
} else {
function declaration() {
return "second";
}
}
declaration();
;; add marmalade to ELPA
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/"))
(package-initialize)
# vim: set fileencoding=utf-8 :
from __future__ import absolute_import, division
from sqlalchemy import (
create_engine,
Column,
Integer,
)
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
@danielholmstrom
danielholmstrom / crash_syslog.py
Created January 31, 2013 18:09
Crash syslog.syslog() in python by logging an empty zip-file.
"""How to crash syslog.syslog
File: crash_syslog.py
Running this will product this output:
Traceback (most recent call last):
File "./crash_syslog.py", line 12, in <module>
syslog(LOG_INFO, base64.b64decode(b64))
TypeError: [priority,] message string
<?php
$str =<<<XML
<?xml version="1.0">
<books>
<book/>
</books>
XML;
$parts = explode("\n", $str, 2);
DISTFILE=$(shell realpath ./build)/minimal-linux-home.tgz
dist: FORCE
rm -f $(DISTFILE) && cd home/ && tar -zcf $(DISTFILE) .*
FORCE:
Output:
DISTFILE=$(shell realpath ./build)/minimal-linux-home.tgz
dist: FORCE
rm -f $(DISTFILE) && cd home/ && tar -zcf $(DISTFILE) .*
FORCE: