Skip to content

Instantly share code, notes, and snippets.

View AlejandroSilva's full-sized avatar
🐰

Alejandro Silva AlejandroSilva

🐰
View GitHub Profile
@AlejandroSilva
AlejandroSilva / gist:9dab7d1b2c7cd292509a5045084738e9
Created March 17, 2018 07:17
[Typescript] [NodeJs] [PostgreSQL] make raw queries with the 'pg' client, and return Promises
import {QueryResult, Client} from 'pg'
const doQuery = (query: string): Promise<QueryResult>=>{
return new Promise((resolve, reject)=>{
const client: Client = new Client(clientConfig)
client.connect((connectError: Error)=>{
if(connectError)
return reject(connectError.message)
client.query(query, (queryError: Error, queryResult: QueryResult)=>{
@AlejandroSilva
AlejandroSilva / gist:86e1ed88c1ce7b4fbb202d9c3178a980
Last active September 18, 2017 07:58
nginx 1.12.1 with pagespeed module loaded dinamically
## INSTALL NGINX
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
## ADD PAGESPEED DINAMICALLY
(from https://github.com/itbdw/nginx_pagespeed_dynamic_module)
cd /etc/nginx
sudo wget https://github.com/itbdw/nginx_pagespeed_dynamic_module/blob/master/nginx_versions/1.12.1/ngx_pagespeed.so?raw=true
sudo mv ngx_pagespeed.so?raw=true ngx_pagespeed.so
sudo apt-get update
###### NVM (from https://github.com/creationix/nvm)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
(restart the shell)
nvm install stable
###### echo script
var http = require('http');
## controller:
function action(){
// validate($request).... <- this doesn't work, it doesn't send the named bag to the view
$validator = Validator::make($request->all(), [
'nombre' => 'required|unique:clientes|max:50|min:2',
'nombreCorto' => 'required|unique:clientes|max:10|min:2',
], [
"required" => ':attribute es obligatorio',
"unique" => ':attribute debe ser unico'
@AlejandroSilva
AlejandroSilva / BACKUP_SERVER
Created August 17, 2016 20:04
respaldo diario de archivos
sudo -u backup-operator crontab -e
on crontab, add:
## backup the files every hour
00 * * * * sh /home/backup-operator/backup_files.sh
@AlejandroSilva
AlejandroSilva / daily_backup.sh
Created July 24, 2016 01:11
daily cron + mysql backup + zip file + send mail with SendGrid with the files
#!/bin/bash
# use "gunzip -k file.sql.gz" to unzip and keep the files
echo "INICIANDO RESPALDO...."
DB_USER=backup
DB_PASS=backup
DB_TABLE_1=TABLE_1
DB_TABLE_2=TABLE_2
DAY=$(date +%Y-%m-%d)
TIME=$(date +%H-%M-%S)
@AlejandroSilva
AlejandroSilva / #
Last active October 4, 2016 23:07
GIT Cheat Sheet
########## USO DIARIO ##########
# eliminar un branch remoto
git push --delete origin thebranch
# eliminar un branch local
git branch --delete thebranch
#### otra forma:
# primero eliminar el local
git branch -d mybranch
# luego empujar los cambios al servidor
============== IN THE DEV MACHINE
git remove list
git remote add prod-falp1 ssh://user@domain/home/user/repo.git
git remote -v
// prod-falp1 ssh://user@domain/home/user/repo.git (push)
============== IN THE PROD MACHINE
cd ~
mkdir repo.git && cd repo.git
git init --bare
#!/bin/bash +x
ip=/sbin/iptables
ipPublica="200.111.191.3/29"
redLocal="192.168.1.1/24"
tothEntel="186.67.103.122"
tothMovistar="186.103.220.254"
admins="$tothEntel $tothMovistar $ipPublica $redLocal"
tcpservices=21,22,smtp,80,443,104,8080,5432,5096,8008
# 53 udp, 123 ntp, 161 snmp
@AlejandroSilva
AlejandroSilva / gist:1b267893f41e402ddbbc
Last active August 18, 2016 14:31
Digital Ocean - Ubuntu SetUp
## fijar timezone
timedatectl set-timezone America/Santiago
# instalar git
sudo-apt get install git
git config --global user.email "pm5k.sk@gmail.com"
git config --global user.name "AlejandroSilva"
## create new user
adduser demouser