Skip to content

Instantly share code, notes, and snippets.

@rgs
rgs / conjuncts.pl
Created Oct 31, 2019
Shows all conjunct consonants in devanagari
View conjuncts.pl
#!perl
use 5.18.2;
use strict;
use warnings;
use open ':std', ':utf8';
print " | ";
for my $c (0x0915 .. 0x0939) {
print chr($c)." | ";
}
@rgs
rgs / wasted_memory.pl
Created Apr 30, 2014
A perl function to get the amount of wasted memory on a memcached server
View wasted_memory.pl
sub wasted_memory {
my ($host, $port) = @_;
my @slabstats = `echo stats slabs | nc $host $port`;
my %perslab;
my $total_malloced = 0;
my $total_wasted = 0;
for (@slabstats) {
if (/STAT total_malloced ([0-9]+)/) {
$total_malloced = $1;
@rgs
rgs / gist:7370406
Created Nov 8, 2013
A vim status line item to display git branch name and status of the currently edited file. To be put in the ~/.vimrc.
View gist:7370406
" returns a string <branch/XX> where XX corresponds to the git status
" (for example "<master/ M>")
function CurrentGitStatus()
let gitoutput = split(system('git status --porcelain -b '.shellescape(expand('%')).' 2>/dev/null'),'\n')
if len(gitoutput) > 0
let b:gitstatus = strpart(get(gitoutput,0,''),3) . '/' . strpart(get(gitoutput,1,' '),0,2)
else
let b:gitstatus = ''
endif
endfunc
View falsehood-prices.md

Falsehoods programmers believe about prices

  1. You can store a price in a floating point variable.
  2. All currencies are subdivided in 1/100th units (like US dollar/cents, euro/eurocents etc.).
  3. All currencies are subdivided in decimal units (like dinar/fils)
  4. All currencies currently in circulation are subdivided in decimal units. (to exclude shillings, pennies) (counter-example: MGA)
  5. All currencies are subdivided. (counter-examples: KRW, COP, JPY... Or subdivisions can be deprecated.)
  6. Prices can't have more precision than the smaller sub-unit of the currency. (e.g. gas prices)
  7. For any currency you can have a price of 1. (ZWL)
  8. Every country has its own currency. (EUR is the best example, but also Franc CFA, etc.)
@rgs
rgs / perldoc-wordcloud.pl
Created Mar 22, 2012
A script to create word clouds from perl's core documentation
View perldoc-wordcloud.pl
use strict;
use warnings;
use File::Slurp;
use Image::WordCloud;
for my $file (<perl*.pod>) {
my $text = `pod2text $file`;
my $wc = Image::WordCloud->new();
$wc->words($text);
my $gd = $wc->cloud();
$file =~ s/od$/ng/;