Skip to content

Instantly share code, notes, and snippets.

@jorgemsrs
jorgemsrs / example.sh
Created April 30, 2020 08:14
Mass rename tags and push them with Git
# variation of https://gist.github.com/knu/111055
# Rename tags named #.#.# or v#.#.# to v#.#.# and push the tag changes
git tag -l | while read t; do n="v${t#v}"; echo "$t - $n"; git tag $n $t; git push --tags ; git tag -d $t; git push origin :refs/tags/$t ; done
@jorgemsrs
jorgemsrs / index.js
Last active October 1, 2019 14:51
Node.js example encrypt+decrypt
#!/usr/bin/env node
const crypto = require('crypto');
const ALGORITHM = 'aes-256-cbc';
const ENCRYPTION_KEY = crypto.randomBytes(32); // For example purposes only. This should come from a secure store. Must be 256 bits (32 chars)
const IV_LEN = 16; // For AES this is always 16
// Symmetric encryption
function encrypt(text) {

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@jorgemsrs
jorgemsrs / gist:2902709
Created June 9, 2012 21:49
C++ template
/**
* Templated method that uses a underlying stringstream to perform
* conversions from string references.
*/
template<class T>
static T fromString(const std::string &s) {
std::istringstream stream(s);
T t;
stream >> t;
return t;
@jorgemsrs
jorgemsrs / mysql_get_fragmented_tables.sql
Created July 6, 2011 21:29
Determine MySQL's fragmented tables
SELECT
TABLE_SCHEMA,
TABLE_NAME,
Data_free
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA NOT IN ('information_schema','mysql')
AND Data_free > 0;
@jorgemsrs
jorgemsrs / uptime-script.sh
Created June 14, 2011 10:45
Uptime script
echo -n `date` ' ';curl --write-out "Time Lookup: %{time_namelookup} Time Connect: %{time_connect} Time to FB: % time_starttransfer} Download Size: %{size_download} HTTP Status: %{http_code} Num Connects: %{num_connects} Num Redirects: %{num_redirects}\n" --silent --output /dev/null __YOUR_WEBSITE.domain.tld__HERE >> /tmp/uptime.log
@jorgemsrs
jorgemsrs / git-svn-authors.sh
Created June 13, 2011 15:01
Create Git authors file from SVN repository
#!/usr/bin/env bash
# @author josh nichols
# @link http://technicalpickles.com/posts/creating-a-svn-authorsfile-when-migrating-from-subversion-to-git/
authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
for author in ${authors}; do
echo "${author} = NAME <USER@DOMAIN>";
done