Skip to content

Instantly share code, notes, and snippets.

@daninfpj
daninfpj / mongoid_rename
Last active August 29, 2015 14:15
MONGOID rename columns
## RENAME FIELDS
Model.collection.find({}).update({ '$rename' => { 'old' => 'new' } }, multi: true, safe: true)
@daninfpj
daninfpj / active.xml
Created October 5, 2017 17:16
ActiveMQ Consumer Ruby
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
<transportConnector name="stomp" uri="stomp://localhost:61613"/>
</transportConnectors>
@daninfpj
daninfpj / code.rb
Last active May 9, 2018 12:56
Generate random code
chars = ('a'..'z').to_a + (0..9).to_a
chars.shuffle.sample(4).join
@daninfpj
daninfpj / gist:d04151052adb64de54fff5048f4b4a63
Created September 12, 2018 16:37
Run rubocop on git changes
git status --porcelain | grep -E '^( |\?)(M|\?).*.rb' | cut -c4- | xargs rubocop -a
@daninfpj
daninfpj / ruby-vscode.md
Last active March 29, 2019 15:02
Setting up Ruby linting, formatting and debugging in VSCode
@daninfpj
daninfpj / .bash_profile
Created June 6, 2019 17:14
venv auto activate
function cd {
builtin cd "$@"
if [ -d ".venv" ] ; then
source .venv/bin/activate
fi
}
@daninfpj
daninfpj / abandoned_branches.sh
Last active June 27, 2019 15:24
Git remote “abandoned” branches
git branch -a --no-merged | grep remotes/origin | grep -v master | grep -v development | xargs git show -s --pretty=format:"%ai %d %an"
@daninfpj
daninfpj / movement.dart
Created June 28, 2019 19:10
Polymorphism
class Movement {
String get status => 'COMPLETED';
bool get isForeignCurrency => false;
}
class Deposit extends Movement {}
class Charge extends Movement {
String status;
@daninfpj
daninfpj / print.py
Created November 29, 2019 00:03
SQLAlchemy print query
from sqlalchemy.dialects import postgresql
print(statement.compile(dialect=postgresql.dialect()))
@daninfpj
daninfpj / print.py
Last active November 29, 2019 00:12
SQLAlchemy print query
from sqlalchemy.dialects import postgresql
print(statement.compile(dialect=postgresql.dialect()))
from sqlalchemy.engine.default import DefaultDialect
from sqlalchemy.sql.sqltypes import String, DateTime, NullType
# python2/3 compatible.
PY3 = str is not bytes
text = str if PY3 else unicode
int_type = int if PY3 else (int, long)