Skip to content

Instantly share code, notes, and snippets.

View hrstt's full-sized avatar

sato hiroyuki hrstt

View GitHub Profile
@hrstt
hrstt / git-diff-zip.sh
Created October 30, 2011 22:12 — forked from func09/git-diff-zip.sh
Gitで特定のコミットからの差分ファイルだけ抜き出してZipにする
git archive --format=zip --prefix=projectname/ HEAD `git diff --name-only <commit>` -o archive.zip
@hrstt
hrstt / monotone_print.xls
Created October 12, 2011 05:20
Excel VBA: シートまたぎの印刷をすべて白黒にするマクロ
Sub MonotonePrint()
Dim Current As Worksheet
For Each Current In Worksheets
' 印刷設定を白黒に
Current.PageSetup.BlackAndWhite = True
Next
' ブック印刷
ActiveWorkbook.Worksheets.PrintOut
@hrstt
hrstt / script_engine_check.js
Created October 7, 2011 04:55
JScript: IEのJScript.dll バージョン表示
// JScript.dll(IE) version check script
function getScriptEngineInfo(){
var s = ScriptEngine() + " Version ";
s += ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion() + "." + ScriptEngineBuildVersion();
return(s);
}
alert(getScriptEngineInfo());
@hrstt
hrstt / format_decimal.js
Created September 5, 2011 06:34
javascript: 数字の桁揃え
// repeat character
String.prototype.repeat = function(num) {
return new Array(num + 1).join(this);
}
// convert strings and filling zero
String.prototype.decimalf = function(num) {
if (isNaN(this) || isNaN(num) || num < 0){ return this;};
ary = this.split(".");
if(num == 0) { return ary[0]; };
ary[1] = (((ary.length>2)? ary[1] : "") + "0".repeat(num)).substring(0,num);
@hrstt
hrstt / jquery_indices_object_reverse.js
Created September 5, 2011 02:42
jQuery: 複数オブジェクトの逆順並べ
$(function(){
// same class name jQuery object
$('div.some_class');
// these reverse indices jQuery object
// Once get indexed objects to array,
// Then use Array.reverse() to descending order.
// At last, convert array object to jQuery object.
$($('div.some_class').get().reverse());
});
@hrstt
hrstt / string_array_outer_product.rb
Created August 30, 2011 08:17
Ruby: 配列同士の総当り組み合わせ
# Array#map
def cross(a, b)
a.map{|elem_a| b.map{|elem_b| elem_a.to_s + elem_b.to_s}}.flatten
end
# Array#product
def cros(a,b)
a.product(b).map{|elem| elem.join()}
end
@hrstt
hrstt / ruby_hash_initial_block.rb
Created August 30, 2011 08:05
Ruby: Hash初期化でブロックを利用.各要素に空配列を用意する
hash = Hash.new{|h,k| h[k] = []}
hash[:test] << "Hello" #=> {:test => ["Hello"]}
@hrstt
hrstt / gist:1175988
Created August 27, 2011 23:16
error brew install io
==> Cloning https://github.com/stevedekorte/io.git
Updating /Users/hsato/Library/Caches/Homebrew/io--git
git remote set-url origin https://github.com/stevedekorte/io.git
git fetch origin
git reset --hard
HEAD is now at c83f98e Merge pull request #129 from jcowgar/master
git checkout-index -a -f --prefix=/private/tmp/homebrew-io-HEAD-VDm0/
==> Downloading patches
==> Patching
/usr/bin/patch -f -p1 -i 001-homebrew.diff
@hrstt
hrstt / gist:1119133
Created August 1, 2011 22:19
extract duplicate value in array
a = [1,2,3,4,5,6,4,5]
a.inject(Hash.new 0) {|h,v| h[v]+= 1;h}.select {|h,v| v >= 2}.keys #=> [4,5]
x = { "one" => "one", "two" => "two", "three" => "three"}
y = x.reject {|key,value| key == "three" }
y == { "one" => "one", "two" => "two"}