Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
use Mojolicious::Lite;
use File::Basename;
use Plack::Builder;
use HTML::TreeBuilder::XPath;
use DBI;
get '/' => sub {
my $self = shift;
#!/bin/sh
_RSS=0
_SHARED=0
_PID=$1
_SMAPS=`cat /proc/$_PID/smaps`
for i in `echo "$_SMAPS" | grep 'Rss' | awk '{print $2}'`; do
_RSS=`expr $_RSS + $i`
done
#!perl
use strict;
use warnings;
use Furl;
use Imager;
use Text::AAlib qw(:all);
my $url = 'https://2.gravatar.com/avatar/0e2fa4d5e82a2addb50f03414870ea46?d=https%3A%2F%2Fidenticons.github.com%2F76d9ed40d8b87622cbfa7bc12cffbcdb.png&s=420';
my $ua = Furl->new;
@nkwhr
nkwhr / pdiff.pl
Created April 2, 2014 16:12
paste diff
#!perl
use sane;
use Text::Diff;
my ($a, $b) = '';
system 'clear';
say 'Paste A (Ctrl-D to end)';
#!perl
use sane;
use Config::Pit;
use LWP::UserAgent;
die unless @ARGV;
my $message = $ARGV[0];
@nkwhr
nkwhr / logrotate
Created April 3, 2014 08:21
logrotate configuration file for Rails (or Mojolicious) applications.
/path/to/app/log/*.log {
weekly
missingok
rotate 12
dateext
compress
delaycompress
notifempty
copytruncate
}
@nkwhr
nkwhr / run.sh
Created April 3, 2014 08:26
helper script for executing plenv + carton app in cron.
#!/bin/sh
export HOME="/home/me"
export PATH="$HOME/.plenv/bin:$PATH"
eval "$(plenv init -)"
cd $HOME/app
exec carton exec -- "$1"
@nkwhr
nkwhr / partition.rb
Last active February 2, 2022 13:55
a serverspec resource type for checking partitions.
module Serverspec
module Type
class Partition < Base
def initialize(partition, type)
@name = partition
@partition_table = {}
case type
when 'cylinder'
options = "-l"
@nkwhr
nkwhr / supervise.rb
Last active August 29, 2015 13:58
a serverspec resource type for checking services running under daemontools.
module Serverspec
module Type
class Supervise < Base
def initialize(name)
@name = name
end
def status
ret = backend.run_command("svstat /service/#{@name} | awk '{print $2}'")
ret[:stdout].chomp
@nkwhr
nkwhr / application.rb
Created May 6, 2014 14:24
Rack middleware for deleting 'Set-Cookie' headers.
module MyApp
class Application < Rails::Application
config.autoload_paths += %W(#{config.root}/lib)
config.middleware.insert_before ActionDispatch::Cookies, "CookieFilter"
end
end