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
#put in lib/tasks/fixtures.rake | |
namespace :db do | |
namespace :fixtures do | |
desc 'Create YAML test fixtures from data in an existing database. | |
Defaults to development database. Set RAILS_ENV to override.' | |
task :dump => :environment do | |
sql = "SELECT * FROM %s" | |
skip_tables = ["schema_migrations"] | |
ActiveRecord::Base.establish_connection(:development) | |
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name| |
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
#!/bin/bash | |
eval 'find app/views app/controllers app/models -type f -exec sed -i "s/ $1[^s\"]/ ConstrBase::&/g" {} \;' | |
eval 'find app/views app/controllers app/models -type f -exec sed -i "s/ConstrBase:: $1/ConstrBase::$1/g" {} \;' | |
git diff | |
echo -n "Here be dragons. Continue?" | |
read REPLY | |
if [[ "$REPLY" =~ ^[Yy]$ ]] | |
then |
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
# in Vim | |
:args ~/src/myproject/**/*.ttl | argdo execute "normal gg=G" | update |
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
#!/bin/bash | |
# For loop to exeute some task multiple times | |
for i in Item1 Item2 ItemN; do | |
bash ~/task.sh ${i} | |
done | |
for i in {1..10} | |
do | |
wget https://static.generated.photos/vue-static/human-generator/poses/female/00$i.png |
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
var exampleDictionary = ["foo":1,"bar":2] | |
// an optional type means its value can either be some certain type or nothing at all( nil) | |
var optionalTypeVariable: Int? = exampleDictionary["someUncertainValue"] | |
// calling optionalTypeVariable will either return an integer or a nil, so you should normally check it’s value before actually using it | |
if optionalTypeVariable == nil { | |
println("The value of optionalTypeVariable is nil") | |
} else { | |
// calling optionalTypeVariable! will always return an integer, if optionalTypeVariable is in fact nil, then an assertion will be triggered. |
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
# syntax: ModelName.joins(:association_name).where({joining_table_name: {column_name:"column value"}}) | |
ContactField.joins(:contact_field_type).where({constr_base_contact_field_types: {name:"Email"}}) |
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
# in normal mode | |
con |
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
curl -i -F name=test -F [email protected] http://example.org/upload |
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
ConstrBase::Trade.find_each do |trade| | |
if matches = /^((\S+\s+)+(\S*))\s*$/.match(trade.name) | |
trade.name = matches[1] | |
trade.save | |
end | |
end |
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
if model A has one or many model B( equals model B belongs to model A), to update index of A when B gets updated, just write in B: | |
belongs_to A, touch: true | |
if model A belongs to model B( equals model B has one or many model A), to update index of A when B gets updated, just write in B: | |
has_many :As | |
after_update { self.As.each(&:touch) } | |
if model A has and belongs to many model B, to update index of A when one of Bs gets updated, just write in A | |
has_and_belongs_to_many :Bs, after_add: [ lambda { |a,c| a.__elasticsearch__.index_document } ], | |
after_remove: [ lambda { |a,c| a.__elasticsearch__.index_document } ] |