Create 3 top-level directories. Create a file and a directory in each.
$ mkdir r rx x
$ touch {r,rx,x}/file
$ mkdir {r,rx,x}/dir
require 'yaml' | |
$db_file = 'filename.yaml' | |
def load_data | |
text = File.read 'db.yaml' | |
return YAML.load text | |
end | |
def store_data hash |
// without callback | |
Array.prototype.eachSlice = function (size){ | |
this.arr = [] | |
for (var i = 0, l = this.length; i < l; i += size){ | |
this.arr.push(this.slice(i, i + size)) | |
} | |
return this.arr | |
}; | |
[1, 2, 3, 4, 5, 6].eachSlice(2) |
// https://developer.mozilla.org/ja/New_in_JavaScript_1.7#Array_comprehensions | |
function range (begin, end) { | |
for (let i = begin; i < end; ++i) { | |
yield i; | |
} | |
}; | |
// http://code.activestate.com/recipes/347689-ruby-arrayeach_cons-each_slice-overlapping-and-non/ | |
function each_cons (l, n) { | |
return [l.slice(i, i + n) for (i in (range(0, l.length - n + 1)))] |
a.group_by{|x| x}
is similar to a.group_by(&:itself)
a.group_by(&:itself)
is a short cut for a.group_by(&:itself.to_proc)
a.group_by(&:itself.to_proc)
just use new Proc
a.group_by(&Proc.new{|o| o.send :itself})
a.group_by(&Proc.new{|o| o.send :itself})
use &
to treat a Proc
as block
like this a.group_by{|o| o.send :itself}
a.group_by{|o| o.send :itself}
here it's possible to substitute o.send :itself
to o.itself
: a.gruop_by{|o| o.itself}
a.group_by{|o| o.itself}
here o.itself
it's just an o
so it's equal to a.group_by{|o| o}
a.group_by{|o| o}
is just a a.group_by{|x| x}
class Solution: | |
def plusOne(self, digits: List[int]) -> List[int]: | |
s = "".join([str(d) for d in digits]) | |
i = int(s) | |
i = i + 1 | |
s = str(i) | |
return [int(si) for si in s] | |
# Definition for singly-linked list. | |
# class ListNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.next = None | |
class Solution: | |
def deleteDuplicates(self, head: ListNode) -> ListNode: | |
cur = head |
# Component way of adding redis | |
# vendor/dry/system/components.rb | |
Dry::System.register_provider( | |
:persistence, | |
boot_path: Pathname(__dir__).join('components').realpath() | |
) | |
# vendor/dry/system/components/redis.rb | |
Dry::System.register_component(:redis, provider: :persistence) do | |
init do |
/** | |
* Definition for a binary tree node. | |
* function TreeNode(val) { | |
* this.val = val; | |
* this.left = this.right = null; | |
* } | |
*/ | |
/** | |
* @param {TreeNode} root | |
* @param {number} key |
#!/usr/bin/env ruby | |
=begin | |
install Sinatra: gem install sinatra | |
install Shotgun: gem install shotgun (this auto-reloads sinatra on every http request - which means every time you make a change in your code you don't have to stop then start sinatra) | |
To just run your code using Sinatra: ruby name-of-file.rb | |
To run your code using Shotgun (which is just Sinatra but with ability to auto-reload when changes are made to files): shotgun name-of-file.rb | |
The following examples are run using Shotgun and the URL is: http://127.0.0.1:9393/ |