Skip to content

Instantly share code, notes, and snippets.

@hanabokuro
hanabokuro / Vagrantfile
Created August 18, 2014 11:11
vagrantfile for apache storm - * not work yet *
# -*- mode: ruby -*-
VAGRANTFILE_API_VERSION = "2"
SERVERS = [
{ hostname: "storm", ssh_forward: 2302, networks: [ { ip: "192.168.0.2", virtualbox__intnet: "storm" } ] },
{ hostname: "nimbus", ssh_forward: 2303, networks: [ { ip: "192.168.0.3", virtualbox__intnet: "storm" } ] },
{ hostname: "server1", ssh_forward: 2304, networks: [ { ip: "192.168.0.4", virtualbox__intnet: "storm" } ] },
{ hostname: "server2", ssh_forward: 2305, networks: [ { ip: "192.168.0.5", virtualbox__intnet: "storm" } ] },
{ hostname: "server3", ssh_forward: 2306, networks: [ { ip: "192.168.0.6", virtualbox__intnet: "storm" } ] },
]
@hanabokuro
hanabokuro / shuffle.rb
Created July 26, 2014 23:06
これだと偏る
#! /usr/bin/env ruby
require 'pp'
def shuffle(array)
i = array.length
while 0 < i
i = i - 1
j = (Random.rand * i).to_i
array[i], array[j] = array[j], array[i]
@hanabokuro
hanabokuro / gist:ff0ae98ffd84bd504364
Last active August 29, 2015 14:02
111111 * 111111 = ?
(2..36).each do |base|
n = '1' * (base - 1)
puts "base: #{base} #{n} * #{n} = #{(n.to_i(base) ** 2).to_s(base)}"
end
@hanabokuro
hanabokuro / bonjovis.rb
Created June 3, 2014 07:04
Bon Jovis Generator
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
words = %w(ボ ン ジョ ヴィ)
targets = %w(ジョ ン ボ ン ジョ ヴィ)
recent = []
num_generate = 0
begin
num_generate += 1
@hanabokuro
hanabokuro / string.rb
Last active September 22, 2015 19:09
String#undump
class String
def undump
self.sub(/\A"/, '').sub(/"\z/, '').gsub(/\\(x([0-9a-f]{2})) | \\(u\{([0-9a-f]{4})\}) | \\(.) /ix) {
if $1 # \xXX
[$2.hex].pack("C")
elsif $3 # \u{xxxx}
[$4.hex].pack("U")
else # \.
case $5
when 't'
(define-key minibuffer-local-filename-completion-map "\C-l" '(lambda () (interactive) (insert-string (concat (helm-reduce-file-name (delete-and-extract-region (minibuffer-prompt-end) (point-max)) 1 ) "/"))))
@hanabokuro
hanabokuro / gist:7924089
Created December 12, 2013 06:52
get url from magit log
(defun dev-gitweb-diff-url-from-magit ()
(interactive)
(let* (
(branch (magit-get-current-branch))
(remote (and branch (magit-get "branch" branch "remote")))
(remote-rebase (and branch (magit-get-boolean "branch" branch "rebase")))
(remote-branch (or (and branch (magit-remote-branch-for branch)) branch))
(remote-string (and remote remote-branch (magit-remote-string remote remote-branch remote-rebase)))
(remote-url (and remote (magit-get "remote" remote "url")))
@hanabokuro
hanabokuro / gist:7410579
Last active December 27, 2015 23:59
Text::Xslate. conbined utf string & utf bytes.
#!perl
use strict;
use warnings;
BEGIN{
# $ENV{XSLATE} = ' dump=ast '; # @@@ @@@
}
use Text::Xslate;
@hanabokuro
hanabokuro / cperl-mode : package.snippet
Created September 20, 2013 12:43
snippet for perl. expand "package".
# -*- mode: snippet -*-
# name: package
# key: package
# --
package ${1:`(if (string-match "/lib/\\(.*\\)\\.pm" buffer-file-name) (replace-regexp-in-string "/" "::" (match-string 1 buffer-file-name)) "")`};
use strict;
use warnings FATAL => qw(all);
$0
@hanabokuro
hanabokuro / toggle-camelcase-snakecase.el
Created September 20, 2013 12:39
toggle camelcase and snakecase.
(defun toggle-camelcase-and-snakecase ()
(interactive)
(let (start end bounds)
(if (and transient-mark-mode mark-active)
(progn
(setq start (mark))
(setq end (point)))
(let ((bounds (bounds-of-thing-at-point 'symbol)))
(when bounds