Skip to content

Instantly share code, notes, and snippets.

@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,
#!/usr/bin/env perl
use sane;
use Redis::Fast;
use Time::Piece;
use DDP;
my $user_id = 100;
my $u = UserLastAccess->new(user_id => $id);
@nkwhr
nkwhr / install_kernel.sh
Created October 29, 2014 09:12
Build and installs vanilla kernel on CentOS 6. You can specify a version with `$VERSION` environment variable.
#!/bin/bash
set -e
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
export LANG=C
if [ $UID -ne 0 ] ; then
echo "You must be root to run this script."
exit 1
#!/bin/bash
PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH
function pushover() {
curl -s -X POST \
--form-string "token=$PUSHOVER_TOKEN" \
--form-string "user=$PUSHOVER_USER" \
--form-string "title=RabbitMQ Restart Attempted" \
@nkwhr
nkwhr / manual_gc.txt
Created December 11, 2014 09:54
Manual GC command for RabbitMQ Server
rabbitmqctl eval '[garbage_collect(P) || P <- processes()].'
@nkwhr
nkwhr / docker_registry_howto.md
Last active August 29, 2015 14:13
How to setup and run private docker registry with Nginx and fig on CentOS6

Download registry container

$ docker pull registry

Install fig

$ sudo yum install python-pip