Skip to content

Instantly share code, notes, and snippets.

View pateketrueke's full-sized avatar

Alvaro Cabrera Durán pateketrueke

View GitHub Profile
@pateketrueke
pateketrueke / stderr_logger.php
Created July 19, 2012 18:16
Logging for PHP with STDERR (Heroku compliant)
<?php
defined('STDERR') OR define('STDERR', fopen('php://stderr', 'w'));
logger::implement('write', function ($type, $message) {
$remote = server('REMOTE_ADDR');
$message = preg_replace('/[\r\n]+\s*/', ' ', $message);
fputs(STDERR, "$remote [$type] $message\n");
});
@pateketrueke
pateketrueke / install.sh
Last active October 7, 2015 10:47
Apache 2.2.24 & PHP 5.4.14 / Heroku pre-compile script
mkdir -p /app
# Prepare the filesystem
mkdir -p /tmp/build
cd /tmp/build
# Compiling Apache
curl http://www.us.apache.org/dist/httpd/httpd-2.2.24.tar.gz | tar xzf -
@pateketrueke
pateketrueke / php_ext.sh
Created July 20, 2012 19:24
PHP extension compile skeleton / Heroku
cd /tmp
curl http://pecl.php.net/get/mongo/1.2.11 | tar xzf -
cd mongo-1.2.11
/app/php/bin/phpize
./configure --with-php-config=/app/php/bin/php-config
make && make install
cd ..
@pateketrueke
pateketrueke / wp-shot.php
Created August 9, 2012 23:13
Take screenshot using WP Remote API (fake)
<?php
$url = urlencode('http://wordpress.org');
$width = 200;
$request = "http://s.wordpress.com/mshots/v1/$url?w=$width";
echo "Link: $request";
@pateketrueke
pateketrueke / .bashrc
Created August 14, 2012 16:07
Open remote GitHub repository URL
hub(){
REPO="$(git remote -v | grep fetch | sed 's/origin//' | tr ':' '/' | sed 's/.*git@/http:\/\//' | sed 's/.git *([a-z]*)//')"
if [ "$(whereis xdg-open)" ] ; then
cmd="xdg-open"
else
cmd="open"
fi
$cmd "$REPO"
}
@pateketrueke
pateketrueke / db-specs.php
Created September 6, 2012 16:11
Fancy db-handle specs with migrations (unnamed project)
<?php
# through DSN
$db = connect(...);
$tbl = 'my_table';
$col = 'my_column';
@pateketrueke
pateketrueke / region.php
Created October 5, 2012 15:06
Function to retrieve the IP location (fake)
<?php
function region($from)
{
static $url = 'http://www.geoiptool.com/?IP=%s';
$html = file_get_contents(sprintf($url, $from));
$html = strip_tags($html, '<a><span>');
@pateketrueke
pateketrueke / deploy.sh
Created November 7, 2012 22:58
Deploying with RSync (common)
#!/bin/sh
OPTIONS='-avlzC --progress --exclude-from exclude.txt --stats'
TRANSPORT='ssh -p 22'
CONNECTION='user@host.tld'
REMOTE_PATH='/var/www'
eval "rsync $OPTIONS -e '$TRANSPORT' . $CONNECTION:$REMOTE_PATH"
@pateketrueke
pateketrueke / sauce.less
Last active October 12, 2015 13:38
Custom LESS mixins from Habanero
// font-face mixin
.font(@path, @family, @weight: normal, @style: normal) {
@eot: asset-path("@{path}.eot");
@woff: asset-path("@{path}.woff");
@ttf: asset-path("@{path}.ttf");
@svg: asset-path("@{path}.svg");
@font-face {
src: url('@{eot}');
src: local("☺"),
@pateketrueke
pateketrueke / jquery-ujs.js
Last active October 12, 2015 13:38
Basic UJS handler from Habanero; jQuery 1.9.1+
(function($, undefined) {
$ujs = {
token: $('meta[name=csrf-token]').attr('content'),
fire: function(obj, name, data) {
var evt = $.Event(name);
obj.trigger(evt, data);
return evt.result !== false;