Skip to content

Instantly share code, notes, and snippets.

View k14i's full-sized avatar

kt k14i

View GitHub Profile
@k14i
k14i / tmux-pbcopy
Last active August 29, 2015 14:06
tmux-pbcopy
#!/bin/bash
if test x`uname -s` != x'Darwin'; then
exit 0
fi
if test `which reattach-to-user-namespace > /dev/null; echo $?` -ne 0; then
echo 'Error: reattach-to-user-namespace does not found.'
if test `which brew > /dev/null; echo $?` -eq 0; then
echo 'Info: Install reattach-to-user-namespace with homebrew.'
@k14i
k14i / benz_and_cigarette.c
Last active August 29, 2015 14:09
「あそこにベンツが停まってますね」 参考: https://twitter.com/syusui_s/status/534548412889178112
#include <stdio.h>
#include <string.h>
#define BUGGY
#define PRICE_BENZ 6000000
#define PRICE_CIGARETTE 42
#define SEQ_1 "「一日何本くらい煙草をお吸いに?」: "
#define SEQ_2 "「%d本ですね」\n"
@k14i
k14i / setup_cachefilesd.sh
Last active December 17, 2015 18:09
cachefilesd properly works with Gluster's NFS, not only with kernel's one. It would be a waste not to match them up :-) #glusterfs https://twitter.com/keithseahus/status/337902379762601984
#!/usr/bin/env bash
NFS_SERVER=192.168.1.100
MOUNT_POINT=/mnt/nfs
yum install -y cachefilesd
if test `grep 'SELINUX=disabled' /etc/selinux/config > /dev/null; echo $?` -ne 0; then
sed -i 's/^secctx/#secctx/g' /etc/cachefilesd.conf
fi
chkconfig cachefilesd on
@k14i
k14i / set_iptables.py
Created June 27, 2013 07:18
This script makes iptables ACCEPT specific CIDRs in a list file. Python >= 2.4 is required (so this can work on legacy OS like CentOS 5.x). It is good to call this script in the start() function of /etc/init.d/iptables.
#!/usr/bin/env python
import re
import os
file = "/root/etc/iptables/accept/cidr"
regex = re.compile('^([0-9]{1,3})(\.([0-9]{1,3})){3}/[0-9]{1,2}')
os.system("iptables -F")
os.system("iptables -A INPUT -i lo -p all -j ACCEPT")
@k14i
k14i / get_password.sh
Last active December 20, 2015 21:58
You should not save your passwords anywhare and should not forget them! This thesis will be solved only by algorithm.
#!/usr/bin/env bash
DIR=$HOME/etc/get_password
. $DIR/get_password_string.txt
. $DIR/get_password_cycle.txt
ALGORITHM="sha1" # md4, md5, sha, sha1, ripemd160 and so on.
count=1
@k14i
k14i / send_global-ipaddr-info.py
Created August 10, 2013 18:01
This may be useful when you don't use dynamic DNS sevices.
#!/usr/bin/env python
import urllib2
import re
import os
import socket
#hostname = socket.gethostname()
hostname = ""
urlprovider = 'http://www.ugtop.com/'
@k14i
k14i / etc-init.d-dropbox-rhel
Last active December 22, 2015 12:38
An /etc/init.d script for dropbox on RHEL.
#!/usr/bin/env bash
# chkconfig: 345 85 1
# description: Startup script for dropbox daemon
#
# processname: dropboxd
# pidfile: /var/run/dropbox.pid
# config: /etc/sysconfig/dropbox
#
### BEGIN INIT INFO
@k14i
k14i / invitation_happy_birthday_u1_party_spec.rb
Last active December 27, 2015 11:29
An invitation of an event.
# -*- coding: utf-8 -*-
require 'spec_helper'
require 'prime'
arr = []
n = Prime.first ** nil.to_i
foo = Proc.new {|x| x.times do n = Prime.first(n).last end }
bar = Proc.new {|x| arr << [[x] * x] }
Prime.first.times do |i| bar.call(Prime.first ** i) end
arr.flatten.map {|x| foo.call(x)}
@k14i
k14i / prime_31.rb
Last active December 27, 2015 11:29
Just to show a prime number of thirty one in a DRY way without any numerics.
# -*- coding: utf-8 -*-
require 'prime'
arr = []
n = Prime.first ** nil.to_i
foo = Proc.new {|x| x.times do n = Prime.first(n).last end }
bar = Proc.new {|x| arr << [[x] * x] }
Prime.first.times do |i| bar.call(Prime.first ** i) end
arr.flatten.map {|x| foo.call(x)}
puts n
@k14i
k14i / file0.txt
Created December 22, 2013 09:05
ElixirでのMessage Passing入門 ref: http://qiita.com/keithseahus/items/58e9cd53c908dcdb4e76
% iex --sname foo --cookie elixir-example
Erlang R16B02 (erts-5.10.3) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (0.11.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(foo@mba11-keith)1>