Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am AlexanderPavlenko on github.
* I am alerticus (https://keybase.io/alerticus) on keybase.
* I have a public key whose fingerprint is 21A4 17B8 8937 82DE A577 052F BABE D11F BE87 3DB9
To claim this, I am signing this object:
@AlexanderPavlenko
AlexanderPavlenko / gist:1291017
Last active September 27, 2015 15:27
android 2.3, fix "device not provisioned"
$ adb shell
$ cd data/data/com.android.providers.settings/databases
$ sqlite3 settings.db
sqlite> .tables
sqlite> select * from secure;
sqlite> INSERT INTO secure (name, value) VALUES ('device_provisioned', 1);
sqlite> .exit
@AlexanderPavlenko
AlexanderPavlenko / wrap_erb.rb
Created May 8, 2012 17:16
wrap erb template into erb template
#!/usr/bin/env ruby
filename = ARGV[0]
str = File.read filename
blocks = str.split('<%').map{|s| s.empty? ? s : s.split('%>') }.flatten
inside = false
blocks.map do |block|
if inside
block.gsub! '\\', '\\\\\\\\'
block.gsub! '"', '\"'
block.gsub! '#{', '#" %><%= "{" + "'
class Base64ImageWrapper < StringIO
def initialize(data, name=nil)
@name = name || 'image'
@blob = Base64.decode64(data)
super @blob
end
def original_filename
"#@name.#{content_type.split('/').last}"
@AlexanderPavlenko
AlexanderPavlenko / fix.rb
Last active December 12, 2015 03:28
fix PostgreSQL comparison of string and number
module Arel::Visitors
class ToSql
alias :visit_Fixnum :quoted
alias :visit_Bignum :quoted
end
end
module ActiveRecord::ConnectionAdapters
class PostgreSQLAdapter
module FixNumberToStringComparison
f = File.open('/tmp/tr', 'w')
set_trace_func proc {
|event, file, line, id, binding, classname|
if event == "call" or event == "return"
f.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
end
}
require 'timeout'
Timeout.timeout(0.5) do
begin
sleep 1
rescue Exception => ex
puts ex.inspect
puts 'ಠ_ಠ'
end
end
@AlexanderPavlenko
AlexanderPavlenko / buggy_enumerator.rb
Created July 25, 2013 10:02
JRuby's Enumerator#to_enum rebinds instance variables to another context?
class BuggyEnumerator < Enumerator
def initialize(that)
@ivar = that
end
def each
return to_enum(:each) unless block_given?
@ivar.each{|item| yield item }
end
end
@AlexanderPavlenko
AlexanderPavlenko / gist:6078702
Created July 25, 2013 11:00
values_at vs. map
require 'benchmark'
n = 1000
Benchmark.bm do |bm|
keys = (1..10000).to_a
hash = Hash[keys.zip(keys)]
bm.report do
n.times do
keys.map{|key| hash[key] }
@AlexanderPavlenko
AlexanderPavlenko / gist:7099831
Created October 22, 2013 12:32
replace static links to less methods
([^-])url\(.*?/img/([^'")]+).*?\)
$1image-url('$2')