Skip to content

Instantly share code, notes, and snippets.

Hiten Parmar hrp

Block or report user

Report or block hrp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View sort-time.rb
#!/usr/bin/ruby
require 'benchmark'
puts "Running Ruby #{RUBY_VERSION}"
ary = []
200.times {
ary << {:bar => Time.at(rand * Time.now.to_i)}
}
View us.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hrp
hrp / kill-postgres
Created Dec 10, 2015
Force kill postgres on OS X El Capitan
View kill-postgres
pg_ctl -D /usr/local/var/postgres -m immediate stop
@hrp
hrp / stack_qa
Created Feb 10, 2015
Stackosaurus Rex
View stack_qa
# Design a data structure supporing the following:
# 1) Push an element
# 2) Pop an element
# 3) Find Minimum in the data structure
# Push(12)
# 12
# Min() ==> 12
View gist:f9b26f81aab86a291bb2
/* Prototype JavaScript framework, version 1.7
* (c) 2005-2010 Sam Stephenson
*
* Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://www.prototypejs.org/
*
*--------------------------------------------------------------------------*/
var Prototype = {
View emojibomb.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
# Run `emojibomb` to get three emoji.
# Run `emojibomb N`, where `N` is a positive integer to get N emoji.
doc = Nokogiri::HTML(open("http://www.emoji-cheat-sheet.com/"))
emoji = doc.css('.name')
@hrp
hrp / acts-as-taggable-speed.rb
Last active Jan 3, 2016
acts-as-taggable-on speed hack
View acts-as-taggable-speed.rb
module ActsAsTaggableOn
mattr_accessor :ignore_case_for_mysql
@@ignore_case_for_mysql = false
class Tag
class << self
def named_any_with_ignore_case(list)
if ActsAsTaggableOn.ignore_case_for_mysql
where(list.map { |tag| sanitize_sql(["name = ?", tag.to_s.mb_chars.downcase]) }.join(" OR "))
else
@hrp
hrp / no-ascii.rb
Created Dec 28, 2013
Dump non-ascii benchmark
View no-ascii.rb
# encoding: utf-8
require 'benchmark'
require 'iconv'
class String
def remove_nonascii(replacement='')
n=self.split("")
self.slice!(0..self.size)
@hrp
hrp / case-insensitive-include.rb
Created Dec 28, 2013
Case insensitive String#include? benchmark
View case-insensitive-include.rb
marking answers to http://stackoverflow.com/questions/9333952/in-ruby-how-to-make-the-string-include-method-ignore-case/9334066
# http://www.gutenberg.org/cache/epub/1661/pg1661.txt
strings = IO.read('sherlock.txt').scan(/\w+/) # 109,222 words
known = 500.times.map do
strings.sample.downcase.chars.map{ |c| rand<0.5 ? c.upcase : c }.join
end
words = known.flat_map{ |s| [s, s+"-"] } # \w does not include -
You can’t perform that action at this time.