Skip to content

Instantly share code, notes, and snippets.

@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 / 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
@nkwhr
nkwhr / update_hosts.sh
Created May 16, 2014 09:52
A handler script for updating /etc/hosts with Serf.
#!/bin/sh
set -e
export PATH=/usr/local/bin:/usr/bin:/bin
read name address role tags
file=/etc/hosts
tmp_file=/tmp/hosts.tmp
@nkwhr
nkwhr / model.rb
Created May 29, 2014 01:20
joinした結果を全て取得するやつ
class Model < ActiveRecord::Base
scope :retrieve_all, ->(*tables) {
select_stmt = [%{`#{self.table_name}`.*}]
select_stmt << tables.map {|t|
ar = ActiveRecord::Base.const_get(t.to_s.classify.singularize)
table_name = ar.table_name
table_name_single = table_name.singularize
ar.attribute_names.map {|col|
@nkwhr
nkwhr / mail.pl
Created June 3, 2014 03:22
Perlでメールを送るときのテンプレート
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Email::Sender::Simple qw/sendmail/;
use Email::MIME;
use Encode;
my $email = Email::MIME->create(
@nkwhr
nkwhr / swap_stats.sh
Last active August 29, 2015 14:02
A shellscript to check who's hogging swap.
#!/bin/sh
## e.g.) sudo ./swap_stats.sh | column -t | sort -nrk3 | head -n25"
if [ $UID -ne 0 ] ; then
echo "You must be root to run this script." 1>&2
exit 1
fi
TOTAL_SWAP=0
@nkwhr
nkwhr / bench.txt
Last active August 29, 2015 14:07
Atlantic.Net Cloud Server GO Plan (CPU:1/MEM:256MB/SSD:10GB) see also: https://speakerdeck.com/mackee/kuraudohuo-yong-shu
# # # # # # # ##### ###### # # #### # #
# # ## # # # # # # # ## # # # # #
# # # # # # ## ##### ##### # # # # ######
# # # # # # ## # # # # # # # # #
# # # ## # # # # # # # ## # # # #
#### # # # # # ##### ###### # # #### # #
Version 5.1.3 Based on the Byte Magazine Unix Benchmark
Multi-CPU version Version 5 revisions by Ian Smith,