Skip to content

Instantly share code, notes, and snippets.

View tamadamas's full-sized avatar
☯️
Love Zig

Tomas Tamadamas tamadamas

☯️
Love Zig
View GitHub Profile
@tamadamas
tamadamas / readme.md
Last active February 13, 2020 09:04
System tips

Kill and restart gpg agent (Fish Shell)

pkill gpg-agent ; gpg-agent --daemon

Sign previous commit

git commit -S --amend

@tamadamas
tamadamas / ruby.rb
Created May 14, 2019 10:27
Rails Typecase from string to boolean
# Rails 5
ActiveModel::Type::Boolean.new.cast('t') # => true
ActiveModel::Type::Boolean.new.cast('true') # => true
ActiveModel::Type::Boolean.new.cast(true) # => true
ActiveModel::Type::Boolean.new.cast('1') # => true
ActiveModel::Type::Boolean.new.cast('f') # => false
ActiveModel::Type::Boolean.new.cast('0') # => false
ActiveModel::Type::Boolean.new.cast('false') # => false
ActiveModel::Type::Boolean.new.cast(false) # => false
ActiveModel::Type::Boolean.new.cast(nil) # => nil
@tamadamas
tamadamas / bash
Created December 17, 2017 18:47
Create new rails project by docker one off ruby container
# Start a new, one-off ruby container running a bash shell. It should have the
# current directory mounted at '/usr/src':
docker run --rm -ti -v $(pwd):/usr/src -w /usr/src ruby:2.2.6 bash
# Now that your'e running bash inside our one-off container, install rails and generate the app.
gem install rails --no-rdoc --no-ri && rails new my-app --database=postgresql
# Exit the one-off container. The container should be removed automatically.
exit
@tamadamas
tamadamas / gen_qrcode.py
Last active February 2, 2018 19:47 — forked from jbinto/howto-recover-google-authenticator-keys.txt
Recovering Google Authenticator keys from Android device for backup
import qrcode
import sqlite3
conn = sqlite3.connect('databases')
c = conn.cursor()
for idx, (email, secret, issuer) in enumerate(c.execute("SELECT email,secret,issuer FROM accounts").fetchall()):
url = 'otpauth://totp/{}?secret={}&issuer={}'.format(email, secret, issuer)
print url
im = qrcode.make(url)
im.save('{}.png'.format(idx))
@tamadamas
tamadamas / ruby_install
Created June 9, 2017 07:40
Rbenv install ruby 2.2.2 in ArchLinux with patched SSLv3 and OpenSSL 1.0 without RDoc
curl -fsSL https://gist.github.com/mislav/055441129184a1512bb5.txt | RUBY_CONFIGURE_OPTS="--disable-install-doc" PKG_CONFIG_PATH=/usr/lib/openssl-1.0/pkgconfig rbenv install --patch 2.2.2
@tamadamas
tamadamas / post-commit
Created October 21, 2015 07:17
Git push on commit
#!/bin/sh
git push origin master
You can apply the patch as a 3-way merge:
git diff 13.1_dev sale_edit > patch.diff
git apply -3 patch.diff
It should bring up the conflict so that you can resolve manually. Or you could go with a one-liner, piping the patch to git-apply directly:
git diff 13.1_dev sale_edit | git apply -3
To reverse the patch:
git diff 13.1_dev sale_edit | git apply -3 -R
@tamadamas
tamadamas / puma.rb
Created June 2, 2015 10:17
Puma default config
workers ENV.fetch('WEB_CONCURRENCY') { 2 }.to_i
threads_count = ENV.fetch('MAX_THREADS') { 5 }.to_i
threads threads_count, threads_count
rackup DefaultRackup
port ENV.fetch('PORT') { 3000 }
environment ENV.fetch('RACK_ENV') { 'development' }
preload_app!
on_worker_boot do
@tamadamas
tamadamas / gist:759efba82eb1ce638d43
Created May 28, 2015 14:36
Convert rails erb views to haml or slim
gem install html2haml
for file in app/views/**/*.html.erb; do html2haml -e $file ${file%erb}haml && rm $file; done
gem install html2slim
for file in app/views/**/*.html.erb; do erb2slim $file ${file%erb}slim && rm $file; done
@tamadamas
tamadamas / convert
Created May 25, 2015 11:26
Convert ruby 1.8 hashes to 1.9 format for all files
find . -name \*.rb -exec perl -p -i -e 's/([^:]):(\w+)\s*=>/\1\2:/g' {} \;