Skip to content

Instantly share code, notes, and snippets.

View yukihr's full-sized avatar
🏠
Working from home

yukihiro hara yukihr

🏠
Working from home
View GitHub Profile
@yukihr
yukihr / shinchoku.coffee
Last active August 29, 2015 13:56
進捗どうですか? on Hubot
# put in scripts/shinchoku.coffee
# add "tumblr": "~0.4.0" on package.json -> "dependencies"
tumblr = require 'tumblr'
util = require 'util'
auth =
# Set these on environment variables
consumer_key: process.env['TUMBLR_CONSUMER_KEY']
consumer_secret: process.env['TUBMLR_CONSUMER_SECRET']
token: process.env['TUMBLR_TOKEN']
#!/bin/sh
#hoard.sh: Private twitter on the shell
#usage:
# hoard "some string here": for store your hoard into file
# hoard -s: hoard: for See your recent hoard
# hoard -e: for Edit your recent hoard
#Change these lines for your System.
hoarddir="/Users/$USER/Documents/Hoard/"
hoardfile="`date +%Y%m`.txt"
// access nested hash data using string
// Usage:
// var hash = {"foo": {"bar": true, "baz": false }};
// getVal(hash, "foo.bar".split(".")); //=> true
// getVal(hash, "foo.baz".split(".")); //=> false
// setVal(hash, "foo.baz".split("."), "hoge"); //=> "hoge"
// you can also create new keys step by step (same as accessing with array-style)
function getVal(hash, keys) {
var frst=keys.splice(0,1);
if(keys.length) {
@yukihr
yukihr / xmltext.rb
Created July 11, 2011 04:58
ruby command which extract text from xmlfile
#!/usr/bin/env ruby
# extract text node from xml file
# USAGE:
# xmltext.rb file_path xpath
require "rexml/document"
file = ARGV.shift.dup
xpath = ARGV.shift.dup
@yukihr
yukihr / coffee-run-file-saving.el
Created July 24, 2011 16:07
run coffee script file bound to current buffer
(defun coffee-run-file-saving ()
"Run coffee script in current buffer in new window"
(interactive)
(if buffer-file-name
(progn
(save-buffer)
(set-buffer
(apply 'make-comint "CoffeeRun"
coffee-command nil (cons buffer-file-name '())))
@yukihr
yukihr / recursivePush.js
Created October 18, 2011 09:56
push to array recursively
function recursivePush(arr, val) {
var execPush = false;
arr.forEach(function(_v) {
if(_v instanceof Array) {
recursivePush(_v, val);
} else {
execPush = true;
}
});
if(execPush || !arr.length) { arr.push(val); };
@yukihr
yukihr / recurClone.js
Created October 19, 2011 02:58
clone Array recursively
function recurClone(input) {
var output = void(0), i, len;
if(input instanceof Array) {
output = [];
for(i=0,len=input.length; i<len; i++) {
output.push(recurClone(input[i]));
}
} else {
@yukihr
yukihr / gist:1301274
Created October 20, 2011 14:26
Regex to extract google query from location.href
[&?]q=([^&#?]+)(?!.*[&?]q=[^&#?]+)
@yukihr
yukihr / gist:1315679
Created October 26, 2011 07:24
ランダムな要素をフィルタするjQueryメソッド(プラグイン)
(function($){
$.fn.random = function(n) {
var elms = Array.prototype.slice.call(this), option = {
number: 1
}, ret = [];
$.extend(option, { number: n});
n = option.number;
@yukihr
yukihr / gist:1325883
Created October 30, 2011 13:04
get (alphabet) word at point
function wordAtPoint(text, point) {
var wordRx = /[a-zA-Z_]+/, separatorRx = /(\s)/,
words, word, i, len, n;
words = text.split(separatorRx);
for (i = n = 0, len = words.length; i < len; i++) {
if (point < (n += words[i].length)) {
if (wordRx.test(words[i])) {
word = words[i];