Skip to content

Instantly share code, notes, and snippets.

View trejo08's full-sized avatar

Juan Trejo trejo08

View GitHub Profile

Keybase proof

I hereby claim:

  • I am trejo08 on github.
  • I am trejo08 (https://keybase.io/trejo08) on keybase.
  • I have a public key whose fingerprint is 6F87 5D78 88A8 B2FB F5AC B029 DC4D D929 757D 2C02

To claim this, I am signing this object:

## Script to send emails through Python to remote email
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.imagen import MIMEImage
from email.mime.multipart import MIMEMultipart
#def SendMail(ImageFileName):
def SendMail():
to = "email address"
#!/bin/bash
# Collect DBUS_SESSION_BUS_ADDRESS from running process
function set_dbus_adress
{
USER=$1
PROCESS=$2
PID=`pgrep -o -u $USER $PROCESS`
ENVIRON=/proc/$PID/environ
@trejo08
trejo08 / Guide to Enable remote access to admin MySQL
Last active November 3, 2015 02:13
Allowing remote acces to MySQL Step by Step
This is a Guide to Enable remote access to MySQL Server, allowing remote administration and sharing databases.
This guide has been tested in Ubuntu desktop/server 14.04
Run the following commands in a terminal
1- sudo apt-get update
2- sudo apt-get upgrade
3- sudo apt-get install -y mysql-server mysql-common mysql-client libmysqlclient-dev
After mysql has been installed and configured successfully and setted 'root' password, change and comment the following file with an editor(nano, emacs, vi, vim) with 'sudo' logged as admin user or root:
file: sudo nano /etc/mysql/my.cnf
#!/bin/bash
RED='\033[1;31m';
GREEN='\033[1;32m';
NC='\033[0m';
function mainMenu {
while true; do
clear;
echo '';
@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

@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 / 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 / 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 / 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