Skip to content

Instantly share code, notes, and snippets.

View kamilhism's full-sized avatar

Kamil Hismatullin kamilhism

View GitHub Profile
@kamilhism
kamilhism / latency.txt
Created November 29, 2015 13:03 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
def select_from_chosen(item_text, options)
field_id = find_field(options[:from])[:id]
within "##{field_id}_chzn" do
find('a.chzn-single').click
input = find("div.chzn-search input")
item_text.each_char do |char|
input.base.invoke('keypress', false, false, false, false, char.ord, nil);
end
find('ul.chzn-results').click
input.base.invoke('keypress', false, false, false, false, 40, nil); # down arrow
RAILS_ENV=production rake db:setup
# produces the error below.....hmmm.....it's a no-worky
psql:/yourprojectpath/yourproject/db/structure.sql:29: ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/hstore.control": No such file or directory
# hstore postgresql extension needs to be installed, so....
sudo apt-get install postgresql-contrib
# now your extension should be available to enable so log in with psql
psql -d yourproject_production -U yourdbuser -W
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
# use: git lg
@kamilhism
kamilhism / .gitignore
Created January 18, 2013 17:26 — forked from don/.gitignore
.gitignore for visual studio's projects
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
## The quick-and-nasty CVE-2013-0156 Heroku inspector!
## Originally brought to you by @elliottkember with changes by @markpundsack @ Heroku
## Download and run using:
## ruby heroku-CVE-2013-0156.rb
`heroku list`.split("\n").each do |app|
app = app.strip
# Some "heroku apps" lines have === formatting for grouping. They're not apps.
next if app[0..2] == "==="
#!/usr/bin/env ruby
#
# Proof-of-Concept exploit for Rails SQL Injection (CVE-2013-0156)
#
# ## Advisory
#
# https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ/discussion
#
# ## Caveats
#
@kamilhism
kamilhism / readme.md
Last active October 13, 2015 16:27
Refinery new engine guide

How to create new engine in RefineryCMS

Create empty engine & migrate

rails g refinery:engine project title:string description:text
bundle install
rails generate refinery:projects
rake db:migrate
rake db:seed
@kamilhism
kamilhism / gist:3919832
Created October 19, 2012 18:29
test task solve
str = "111222333" * 1000000
a = Time.now
str.scan(/(0+|1+|2+|3+|4+|5+|6+|7+|8+|9+)/).map { |i| "#{i[0].size}#{i[0][0]}" }.join
puts Time.now - a
a = Time.now
str.scan(/((\d)\2*)/).map { |i| "#{i[0].size}#{i[1]}"}.join
puts Time.now - a