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
if Rails::VERSION::MAJOR == 2 | |
require "active_support/core_ext/string/output_safety" | |
class ERB | |
module Util | |
# see https://github.com/rails/rails/issues/7430 | |
def html_escape(s) | |
s = s.to_s | |
if s.html_safe? | |
s |
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 | |
# | |
# redis - this script starts and stops the redis-server daemon | |
# | |
# chkconfig: - 85 15 | |
# description: Redis is a persistent key-value database | |
# processname: redis-server | |
# config: /etc/redis/redis.conf | |
# config: /etc/sysconfig/redis | |
# pidfile: /var/run/redis.pid |
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(kata2). | |
-export([chop/0, chop/2]). | |
% http://stackoverflow.com/questions/1035655/list-is-conceived-as-integer-by-length-function | |
chop() -> chop(6,[2,4,6,8,10]). | |
chop(Result) -> io:format("Location index... ~w~n", [Result-1]). | |
chop(Val, List) -> | |
if List == [] -> | |
-1; |
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
# A B C | |
# B C E | |
# C G | |
# D A F | |
# E F | |
# F H | |
require 'rgl/adjacency' | |
require 'rgl/traversal' | |
require 'rgl/dot' | |
require 'test/unit' |
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
def search_in_hash(hash, target, args={}, keys='ROOT') | |
find_key = (args[:find_key] == true) | |
hash.each do |key, value| | |
find_target = find_key ? key.to_s : value | |
if find_target == target | |
keys = "#{keys} -> '#{key}' => #{target}" | |
puts keys | |
keys = "" | |
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
require 'ruby-debug' | |
class LineCounter | |
def initialize | |
@count = 0 | |
@commenting = false | |
end | |
def lines_of_code(file) | |
@count = 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
def is_token_prefix?(prefix, tokens) | |
tokens.each { |token| return true if token.start_with?(prefix) } | |
false | |
end | |
def is_token?(str, tokens) | |
tokens.each { |token| return true if token == str } | |
false | |
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
def multi_split2(str, delims) | |
multi(str, delims, []) | |
end | |
def multi(str, delims, sum) | |
return sum if str.empty? | |
temp, token = "", "" | |
while !is_token_prefix? str[0], delims | |
token << str[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
require 'ruby-debug' | |
def multi_split(str, tokens) | |
results = [] | |
buffer = "" | |
maybe_token = false | |
temp_str = "" | |
str.each_char do |c| | |
if maybe_token | |
if is_token?(temp_str + c, tokens) |
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
require File.expand_path(File.join(File.dirname(__FILE__), "bloom.rb")) | |
class String | |
def each_char_with_index | |
0.upto(size - 1) do |index| | |
yield(self[index..index], index) | |
end | |
end | |
def remove_char_at(index) | |
return self[1..-1] if index == 0 |