Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
lyoshenka / le_cert.sh
Created February 23, 2016 22:06
Let's Encrypt wrapper. Will create/renew a cert for a single domain, or renew all your certs if they will expire within a given window
#!/bin/bash
if [ -z "${1:-}" ]; then
echo "usage: $0 [DOMAIN|renewall]"
exit 1
fi
# ensure running as root
if [ "$(id -u)" != "0" ]; then
#exec sudo "$0" "$@"
@lyoshenka
lyoshenka / latency.txt
Created February 17, 2016 17:38 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@lyoshenka
lyoshenka / trimtrees.pl
Created January 20, 2016 22:56
trimtrees - traverse directories, find identical files, replace with hard links
#!/usr/bin/perl -w
use strict;
use Cwd;
use Digest::MD5 qw(md5);
use Dumpvalue;
use File::Compare qw(compare);
use File::Copy qw(cp);
use File::Find;
use File::Temp qw(tempfile);
@lyoshenka
lyoshenka / github-octocat-corner.html
Created November 19, 2015 13:34
A nice link to your Github repo
<a href="https://github.com/lyoshenka" class="github-corner">
<svg width="80" height="80" viewBox="0 0 250 250" style="fill:#eee; color:#151513; position: absolute; top: 0; border: 0; right: 0;">
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 15
@lyoshenka
lyoshenka / Lock.class.php
Last active November 6, 2016 15:42
Simple exclusive locks in PHP
<?php
/* HOW TO USE
$lockFile = Lock::getLock('lock-name');
if (is_resource($lockFile)) {
// you have a lock here, do whatever you want
Lock::freeLock($lockFile);
}
@lyoshenka
lyoshenka / shellExec.php
Last active March 7, 2016 18:53
Proper PHP shell exec function. Gets you the return code, stdout, and stderr. Plus lets you you stream the output to stdout/stderr in addition to capturing it.
<?php
/**
* Shell
*
* Execute shell commands properly.
* - forks a separate process to run the command
* - collects all output (including the exit code and stderr) and returns it neatly
* - optionally prints the output/error to stdout/stderr, so you can see it in (almost) real time
*
@lyoshenka
lyoshenka / twerkify-bookmarklet.js
Last active October 22, 2015 19:14 — forked from jacopotarantino/twerkify.js
Twerkify - Make your website twerk.
javascript:!function(){"use strict";function e(){var e,t,a;e=JSON.parse(this.responseText),t=document.querySelectorAll("img"),a=Array.prototype.slice.call(t),a.forEach(function(t){var a=e.data[Math.floor(Math.random()*e.data.length)];t.src=a.images.fixed_height.url})}console.log("Thank you for twerking");var t;t=new window.XMLHttpRequest,t.addEventListener("load",e),t.open("GET","https://api.giphy.com/v1/gifs/search?q=twerking&api_key=dc6zaTOxFJmzC"),t.send()}();
@lyoshenka
lyoshenka / cronic.sh
Created September 5, 2015 01:23
Cronic - A cure for Cron's chronic email problem - http://habilis.net/cronic/
#!/bin/bash
# Cronic v2 - cron job report wrapper
# Copyright 2007 Chuck Houpt. No rights reserved, whatsoever.
# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
set -eu
OUT=/tmp/cronic.out.$$
ERR=/tmp/cronic.err.$$
@lyoshenka
lyoshenka / 45to75.js
Created August 24, 2015 20:08
Bookmarklet to highlight the 45-75 char range. Helps with picking a width for your content.
javascript: (function() {
function loadScript(a, b) {
var c = document.createElement('script');
c.type = 'text/javascript';
c.src = a;
var d = document.getElementsByTagName('head')[0],
done = false;
c.onload = c.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
@lyoshenka
lyoshenka / grinprompt.sh
Last active August 29, 2015 14:27
My simple Bash prompt, before switching to liquidprompt
# Set prompt (including git repo info)
# https://gist.github.com/31631
PROMPT_COMMAND='DIR=`pwd|sed -e "s!$HOME!~!"`; if [ ${#DIR} -gt 50 ]; then CurDir=${DIR:0:22}...${DIR:${#DIR}-25}; else CurDir=$DIR; fi'
if [ -f ~/Dropbox/bash/completion/git ]; then
source ~/Dropbox/bash/completion/git
export GIT_PS1_SHOWDIRTYSTATE=1
PS1='\[\033[0;33m\]$(date +%H%M) \[\033[1;37m\]\h:\[\033[1;36m\]$CurDir\[\033[00m\]$(__git_ps1)\$ '
elif [ -n "$(which git)" ]; then
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"