git clone https://gist.github.com/ishu3101/6fb35afd237e42ef25f9
mv 6fb35afd237e42ef25f9 ConvertTo-Markdown
cd ConvertTo-Markdown
| package main | |
| import ( | |
| "strings" | |
| ) | |
| func main() { | |
| strings.HasPrefix("foobar", "foo") // true | |
| } |
| // 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)))] |
| // 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) |
| require "resolv" | |
| class Model < ActiveRecord::Base | |
| validates :ip_address, format: { with: Resolv::IPv4::Regex } | |
| validates :mac_address, format: { with: /\A([0-9A-F]{2}[-:]){5}([0-9A-F]{2})\z/ } | |
| end |
| require 'fileutils' | |
| # __FILE__ keyword in ruby | |
| puts "The current ruby file being executed is #{__FILE__}" | |
| # Gets the directory name of the file being executed | |
| current_directory = File.dirname(__FILE__) | |
| puts "The current directory is #{current_directory}" | |
| # expands to reveal the pwd (Present working directory) |
| #!/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/ |
| require 'yaml' | |
| $db_file = 'filename.yaml' | |
| def load_data | |
| text = File.read 'db.yaml' | |
| return YAML.load text | |
| end | |
| def store_data hash |
| require 'benchmark/ips' | |
| Benchmark.ips do |x| | |
| Property = Struct.new(:name, :original_name) | |
| PROPERTIES = [ | |
| Property.new("Clo", "Chloe" ), | |
| Property.new("Jon", "Jonathan" ), | |
| Property.new("Kris", "Kristin" ), |