Skip to content

Instantly share code, notes, and snippets.

View peijiehu's full-sized avatar

Peijie Hu peijiehu

View GitHub Profile
@peijiehu
peijiehu / convert_time
Last active August 29, 2015 14:04
Ruby: Convert seconds to H:M:S format
time = 12345678 # seconds
formatted_time = Time.at(time).utc.strftime("%H:%M:%S")
@peijiehu
peijiehu / read_yml
Created September 9, 2014 19:30
Retrieving value from yaml file
# Helper method for retrieving value from yaml file
# @param [String, String]
# keys, eg. "timeouts:implicit_wait" to retrieve value "60" from
# yml file with content:
# timeouts:
# implicit_wait: 60
def read_yml(file_name, keys)
data = Hash.new
begin
data = YAML.load_file "#{file_name}"
@peijiehu
peijiehu / PrintClasspath
Created October 29, 2014 18:07
Print out currentproject classpath
cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)cl).getURLs();
for (URL url: urls) {
System.out.println(url.getFile());
}
@peijiehu
peijiehu / gist:b2da33a1235110c07aea
Created January 15, 2015 21:57
Get number of properties in an object
function arrayLength(obj) {
if (typeof(obj) == 'string') {
return 1;
} else {
return obj.length;
}
}
@peijiehu
peijiehu / method_missing_with_arguments
Created March 2, 2015 20:07
override method_missing and accepts multiple arguments
def method_missing(method_sym, *arguments)
if arguments.empty?
puts method_sym
else
puts "#{method_sym}(#{arguments.join(',')})"
end
end
@peijiehu
peijiehu / rspec-example-path
Created March 3, 2015 19:48
Get an rspec example's path at run time in rspec configure
# can be useful when you are not in that directory, eg. use it in RSpec.configure block
# but you'll need access to the example object
RSpec.configure do |config|
config.before :each do |example|
puts spec_dir = File.dirname(example.metadata[:file_path])
end
end
@peijiehu
peijiehu / check_variable_contains.sh
Last active September 1, 2015 00:28
Shell: check whether a variable contains certain string or not
# to check whether TEST_OPTIONS contains "-P" or "--parallel", or not
# TEST_OPTIONS can be "-P 20", "--parallel=15", or any string
if [[ "$TEST_OPTIONS" == -P* ]] || [[ "$TEST_OPTIONS" == --paralell* ]]; then echo "yes"; else echo "no"; fi
@peijiehu
peijiehu / Find Gem Dependency
Created November 20, 2015 19:26
Find gems that depend on a given gem
# Two ways:
# 1. Print out dependencies of all gems, then search for the 'given gem'
gem list | egrep '^.*[ ]' -o | gem dependency
# 2. Look inside Gemfile.lock
@peijiehu
peijiehu / gist:d34947c1f96b6796bee5
Created December 8, 2015 16:38
Regular expression match condition to launch Sauce Connect on jenkins
Regular expression match condition to launch Sauce Connect on jenkins:
Launch when env ends with "_ci":
Expression: ^.*_ci$
Label: ${ENV,var="HOST_ENV"}
@media (max-width: 479px) {
.show-on-desktop, .show-on-tablets, .hide-on-mobile { display: none; }
}
@media (min-width: 480px) and (max-width: 979px) {
.show-on-desktop, .hide-on-tablets, .show-on-mobile { display: none; }
}
@media (min-width: 980px) {
.hide-on-desktop, .show-on-tablets, .show-on-mobile { display: none; }
}