$ cat mongo_mapper.rb
$ cat mongo_mapper.rb | ruby rewrite.rb
class Foo
include Mongoid::Document
key :name, String
end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Document | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| def key(name, type) | |
| puts "a new key `#{name}` in `#{type}` is declared." | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main(int argc, char **argv) { | |
| for (int i = 0; i < 4; i++) { | |
| int j = i; | |
| printf("&i = %p, &j = %p\n", &i, &j); | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| func main() { | |
| for i := 0; i < 4; i++ { | |
| j := i | |
| fmt.Printf("&i = %p, &j = %p\n", &i, &j) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Place your key bindings in this file to override the defaults | |
| [ | |
| // cycle tabs in the current group with ctrl+tab and ctrl+shift+tab | |
| { | |
| "key": "ctrl+tab", | |
| "command": "workbench.action.nextEditorInGroup" | |
| }, | |
| { | |
| "key": "ctrl+shift+tab", | |
| "command": "workbench.action.previousEditorInGroup" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class String | |
| # byte単位で計算されたインデックスを文字単位に変換する。 | |
| # 文字の途中や、範囲外の値が渡されたらnilを返す。 | |
| # | |
| def byteindex2charindex(byteindex) | |
| return 0 if byteindex == 0 | |
| cur = 0 | |
| codepoints.each.with_index(1) do |codepoint, index| | |
| cur += codepoint.chr(Encoding::UTF_8).bytesize |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require "csv" | |
| path = ARGV[0] | |
| offset = ARGV[1] ? ARGV[1].to_i : 1 | |
| opts = {} | |
| opts[:col_sep] = "\t" if path.end_with?(".tsv") | |
| rows = CSV.read(ARGV[0], opts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class String | |
| def nth_index(pattern, n) | |
| pos = nil | |
| offset = nil | |
| begin | |
| pos = index(pattern, offset || 0) | |
| return nil if pos.nil? | |
| n -= 1 | |
| offset = pos + 1 | |
| end while n >= 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| remote="origin" | |
| if git remote | grep fork >/dev/null 2>&1; then | |
| remote="fork" | |
| fi | |
| branch="$(git rev-parse --abbrev-ref HEAD)" | |
| git push -u $remote $branch |