Skip to content

Instantly share code, notes, and snippets.

View trejo08's full-sized avatar

Juan Trejo trejo08

View GitHub Profile
@trejo08
trejo08 / .screenrc
Created September 29, 2021 02:29 — forked from phawk/.screenrc
Sample screenrc
# Save this in ~/.screenrc
# Use bash
shell /bin/bash
autodetach on
# Big scrollback
defscrollback 5000

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@trejo08
trejo08 / systemd-manager.md
Created February 28, 2020 21:44 — forked from illvart/systemd-manager.md
Install systemd-manager for Ubuntu/Arch Linux

Screenshot_2019-05-20_02-46-48

systemd-manager for ubuntu:

lsb_release -a

Example output:

Distributor ID: Ubuntu
@trejo08
trejo08 / postgresql_configuration_on_ubuntu_for_rails.md
Created May 13, 2018 07:51 — forked from p1nox/postgresql_configuration_on_ubuntu_for_rails.md
PostgreSQL configuration without password on Ubuntu for Rails

Abstract

You could have postgre installed on localhost with password (or without user or password seted after instalation) but if we are developing we really don't need password, so configuring postgre server without password for all your rails project is usefull.

Install Postgre packages

  • postgresql
  • postgresql-client
  • libpq-dev
@trejo08
trejo08 / hash_except.md
Created May 8, 2018 16:35 — forked from O-I/hash_except.md
[TIx 4] Remove key-value pairs from a hash and return the hash

Sometimes I want to remove a specific key-value pair from a Ruby hash and get the resulting hash back. If you're using Rails or ActiveSupport you can accomplish this using Hash#except:

hash = { a: 1, b: 2, c: 3 }
hash.except(:a)     # => { b: 2, c: 3 }

# note, the original hash is not modified
hash                # => { a: 1, b: 2, c: 3 }

# it also works with multiple key-value pairs
@trejo08
trejo08 / solution1.rb
Created April 26, 2018 18:04
How to add or overwrite methods from engine controllers or models in the app that uses the engine.
# This simple solution open-classes the controller/model in the main app
# to add or overwrite methods.
# A drawback of this solution is that you won't be able to access the original
# method by using +super+.
# engine: app/controllers/myengine/my_controller.rb
# This is the controller in our engine with a index method defined.
module MyEngine
class MyController < ApplicationController
def index
@trejo08
trejo08 / ssl_puma.sh
Last active April 26, 2018 17:59 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@trejo08
trejo08 / readme.md
Created March 16, 2018 21:33 — forked from hone/readme.md
Private GitHub repos with Bundler on Heroku

Setting Up Private GitHub Repos with Bundler on Heroku

To get a private GitHub repo to work on Heroku, you can leverage the netrc buildpack in conjunction with the Heroku Ruby buildpack.

When setting up the Gemfile, make sure to use the https GitHub URL. This mechanism does not work with git+ssh.

gem "some_private_gem", git: "https://github.com/org/some_private_gem.git"
@trejo08
trejo08 / Include-in-Sequelize.md
Created December 1, 2017 16:15 — forked from zcaceres/Include-in-Sequelize.md
using Include in sequelize

'Include' in Sequelize: The One Confusing Query That You Should Memorize

When querying your database in Sequelize, you'll often want data associated with a particular model which isn't in the model's table directly. This data is usually typically associated through join tables (e.g. a 'hasMany' or 'belongsToMany' association), or a foreign key (e.g. a 'hasOne' or 'belongsTo' association).

When you query, you'll receive just the rows you've looked for. With eager loading, you'll also get any associated data. For some reason, I can never remember the proper way to do eager loading when writing my Sequelize queries. I've seen others struggle with the same thing.

Eager loading is confusing because the 'include' that is uses has unfamiliar fields is set in an array rather than just an object.

So let's go through the one query that's worth memorizing to handle your eager loading.

The Basic Query