Skip to content

Instantly share code, notes, and snippets.

View lexaurin's full-sized avatar

lex mourek lexaurin

View GitHub Profile
@lexaurin
lexaurin / gist:943887
Created April 27, 2011 08:04
Shows actual git branch on command prompt
#GIT bash by HABR
export PSORIG="$PS1"
function GITCHECK() {
STATUS=$(git status 2> /dev/null)
if [ -n "$STATUS" ] ; then
BRANCH="$(echo "$STATUS" | head -n1 | awk '{print $4}')"
export PS1=$PSORIG$(echo -en "\[\033[01;33m\]$BRANCH > \[\033[00m\]")
else
export PS1="$PSORIG"
@lexaurin
lexaurin / gist:943888
Created April 27, 2011 08:06
Shows actual git branch on command prompt
#GIT bash by HABR
export PSORIG="$PS1"
function GITCHECK() {
STATUS=$(git status 2> /dev/null)
if [ -n "$STATUS" ] ; then
BRANCH="$(echo "$STATUS" | head -n1 | awk '{print $4}')"
export PS1=$PSORIG$(echo -en "\[\033[01;33m\]$BRANCH > \[\033[00m\]")
else
export PS1="$PSORIG"
@lexaurin
lexaurin / .gitconfig
Last active December 11, 2015 11:28
How to manage changelog by git tags? Prefix tags with "v" letter and use this alias:
[alias]
changelog = "!git tag -l v* -n20 | sed -n 'H;${;g;s/\\n[^v]/\\x00/g;p}' | sort -rV | tr \\\\000 \\\\n | less"
phpunit --log-json php://stdout unit/ | awk '$NF ~ '/,/' && $1 ~ /"(test|time)"/' | cut -d: -f2- | sed "N;s/\n/--/" | sed "s/,//"| awk 'BEGIN{FS="--"}; {print $2 $1}' | sort -r | head -n 20
@lexaurin
lexaurin / redis-pipe-bug.php
Last active August 29, 2015 14:17
phpredis "errno=32 Broken pipe" bug
<?php
$redis = new Redis();
var_dump($redis->connect('127.0.0.1'));
echo 'Parent pid: ' . getmypid() . PHP_EOL;
set_error_handler(function($errno, $errstr, $errfile, $errline) {
echo 'Error in PID ' . getmypid() . ': ' . $errstr . PHP_EOL;
});
@lexaurin
lexaurin / formatSizeSI.js
Created December 16, 2015 15:56
Simple & elegant file size formatter
#!/usr/bin/env node
require('v8').setFlagsFromString('--harmony_destructuring');
const assert = require('assert');
function formatSizeSI(size) {
var index = Math.floor(Math.log(Math.abs(size)) / Math.log(1000)) | 0;
return +(size / Math.pow(1000, index)).toPrecision(3) + ' '
+ (index ? 'kMGTPEZY'[--index] + 'B' : 'Bytes');
}
@lexaurin
lexaurin / jessie-mongodb-3-3-x.sh
Last active August 27, 2016 20:44 — forked from hpherzog/jessie-mongodb-3-0-x.sh
Install mongodb version 3.3.x on debian jessie
#!/bin/sh
apt-key adv --keyserver keyserver.ubuntu.com --recv A15703C6
echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.3 main" | tee /etc/apt/sources.list.d/mongodb-org-3.3.list
apt-get update
#apt-get install -y mongodb-org
apt-get install -y mongodb-org-unstable
$$('video').forEach(v => v.playbackRate = 1.4)