$/
artifacts/
build/
docs/
lib/
packages/
samples/
src/
tests/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dpkg: check that unix package is installed. Bash script: install package if not present | |
By neokrates, written on May 21, 2010 | |
Was the package already installed or it still needs to be? | |
Software: | |
✔ Ubuntu * | |
dpkg -s can be used. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format_join(string, joiner=' ') | |
string.split(/\W/).reject(&:empty?).join(joiner.to_s) | |
end | |
# $ ruby -v | |
# ruby 2.1.9p490 (2016-03-30 revision 54437) [x86_64-darwin18.0] | |
# | |
# $ irb | |
# irb(main):001:0> def format_join(string, joiner=' ') | |
# irb(main):002:1> string.split(/\W/).reject(&:empty?).join(joiner.to_s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $ ruby -v | |
# ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18] | |
# $ pwd | |
# /Users/dev/Documents/Github/Gists/awesome/ | |
# $ echo "puts File.expand_path(__FILE__)" > how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb | |
# $ echo "puts File.absolute_path(__FILE__)" >> how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb | |
# $ cat how-to-get-the-name-of-the-current-file-with-directory-filepath.rb | |
# puts File.expand_path(__FILE__) | |
# puts File.absolute_path(__FILE__) | |
# $ ruby how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
touch ~/.android/repositories.cfg | |
brew cask install caskroom/versions/java8 | |
brew cask install android-sdk | |
brew cask install intel-haxm | |
brew install qt | |
export ANDROID_SDK_ROOT="/usr/local/share/android-sdk" | |
sdkmanager "platform-tools" "platforms;android-27" "extras;intel;Hardware_Accelerated_Execution_Manager" "build-tools;27.0.0" "system-images;android-27;google_apis;x86" "emulator" | |
avdmanager create avd -n test -k "system-images;android-27;google_apis;x86" | |
/usr/local/share/android-sdk/tools/emulator -avd test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sql = "SELECT | |
TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME | |
FROM | |
INFORMATION_SCHEMA.KEY_COLUMN_USAGE | |
WHERE REFERENCED_TABLE_SCHEMA = 'awesome_db'" | |
x = ActiveRecord::Base.connection.execute(sql) | |
# remove constraints | |
z = x.map {|y| | |
"remove_foreign_key :#{y[0]}, column: '#{y[1]}', name: '#{y[2]}'\n" + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :database do | |
task fat_tables: :environment do | |
c = ActiveRecord::Base.connection | |
max_table_name_width = 0 | |
tables = c.tables.sort_by do |t| | |
max_table_name_width = t.length if t.length > max_table_name_width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Badger | |
attr_accessor :name, :size # Creates getter and setter methods. | |
def initialize(name, size) | |
@name = name | |
@size = size | |
end | |
# Instance method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controller/articles_controller.rb | |
around_filter { |controller, action| controller.send(:add_published_scope, Article){ action.call } } | |
# app/controller/application_controller.rb | |
def add_published_scope(klass = nil, &block) | |
unless klass | |
klass = controller_name.classify.constantize | |
end | |
klass.with_scope(:find => klass.where("published_at <= ?", Time.zone.now)) do | |
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'base64' | |
filename = "lib/templates/assets/image.jpg" | |
datauri = "data:image/#{File.extname(filename).delete('.')};base64," + Base64.strict_encode64(open(filename).read) |