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(hash, keyword) | |
if (hash.respond_to?(:keys) && hash.keys.include?(keyword)) | |
hash[keyword] | |
elsif hash.respond_to?(:find) | |
result = nil | |
hash.values.find { |value| result = search(value, keyword) } | |
result | |
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
class ActiveRecord::Base | |
class << self | |
def random | |
all.at(rand(count)) | |
end | |
end | |
end | |
# User.random => #<User id: 10, ...> | |
# User.random => #<User id: 59, ...> |
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
# simple camelize in ruby | |
class String | |
def camelize | |
split("_").map(&:capitalize).join | |
end | |
end | |
# "kamesh_test" => "KameshTest" |
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 titleize | |
u_split = split("_") | |
s_split = u_split.map { |s| s.split(" ") }.flatten | |
if s.split.empty? | |
capitalize | |
else | |
s_split.map(&:capitalize).join(" ") | |
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
class String | |
def method_missing(method, *args, &block) | |
method_name = method.to_s | |
if method_name.include?("is_") && method_name.include?("?") | |
method_name = method_name.gsub("is_", "")[0..-2] | |
(method_name == self) || (method_name.camelize == self) || (method_name.titleize == self) || (method_name.gsub(" ", "") == self) | |
else | |
super(method, *args, &block) | |
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
def files(file) | |
return file unless ( file = Pathname.new(file) and File.directory?(file) ) | |
file.children.map { |f| files(f) } | |
end | |
# files(".") => [#<Pathname:hello.rb>, #<Pathname:spec/hello.rb>, #<Pathname:spec/hai.rb>, ...] |
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
SOURCE_APP = ARGV[0] | |
DESTINATION_APP = ARGV[1] | |
if SOURCE_APP.nil? || DESTINATION_APP.nil? | |
puts 'USAGE: ruby copy_heroku_config.rb SOURCE_APP_NAME DESTINATION_APP_NAME' | |
end | |
# Parsing heroku configs | |
configs = `heroku config --app #{SOURCE_APP}` | |
configs = configs.split('\n') |
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
# frozen_string_literal: true | |
# This file defines the configuration for mail reading through pop3 protocol | |
# using 'Mailman' library. Place this file inside `config/initializers` if you are on Rails. | |
# Poll interval must be specified seconds, it defaults to 10 seconds | |
Mailman.config.poll_interval = (ENV['MAILBOX_POLL_INTERVAL'] || 10).to_i | |
# POP3 settings | |
Mailman.config.pop3 = { | |
server: ENV['POP3_SERVER'], |
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
const { Builder, By, until } = require('selenium-webdriver'); | |
const driver = new Builder() | |
.forBrowser('chrome') | |
.build(); | |
const waitForTitle = () => { | |
return driver.getTitle().then((title) => title.includes('JSFiddle')); | |
} | |
const runTests = () => { |
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
window.updateParamAndReload = function(paramName, value) { | |
var url = new URL(window.location.toString()) | |
url.searchParams.set(paramName, value) | |
window.location = url | |
} |
OlderNewer