Skip to content

Instantly share code, notes, and snippets.

(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 / 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 / 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 / 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 / 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 / install_plevn.sh
Last active August 29, 2015 14:07
install plenv
sudo git clone https://github.com/tokuhirom/plenv.git /usr/local/plenv
sudo mkdir /usr/local/plenv/plugins
sudo git clone https://github.com/tokuhirom/Perl-Build.git /usr/local/plenv/plugins/perl-build
sudo sh -c 'PLENV_ROOT=/usr/local/plenv PATH="$PLENV_ROOT/bin/:$PLENV_ROOT/shims:$PATH" plenv install 5.18.2'
sudo sh -c 'PLENV_ROOT=/usr/local/plenv PATH="$PLENV_ROOT/bin/:$PLENV_ROOT/shims:$PATH" plenv install 5.20.1'
sudo sh -c 'PLENV_ROOT=/usr/local/plenv PATH="$PLENV_ROOT/bin/:$PLENV_ROOT/shims:$PATH" plenv install-cpanm'
'use strcit'
var Promise = require('bluebird');
function findUser(id) {
// return Promise.resolve({id: id})
return Promise.reject('not found')
}
var user = findUser(12)
@hanabokuro
hanabokuro / get-string-region-at-cursor
Created August 18, 2015 06:00
Get region of string under cursor
(defun get-string-region-at-cursor ()
(save-excursion
(let (beg)
(setq beg (nth 8 (parse-partial-sexp 1 (point))))
(if beg
(progn
(goto-char beg)
(forward-sexp)
(list (1+ beg) (1- (point))))
nil)
@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'
#!/usr/bin/perl
use strict;
use warnings;
use Text::Xslate;
use Test::More;
my $tx = Text::Xslate->new(cache => 0,
function => {