Skip to content

Instantly share code, notes, and snippets.

View renatoargh's full-sized avatar

Renato Gama renatoargh

View GitHub Profile
sudo sh -c "echo -n 'sammy:' >> /etc/nginx/.htpasswd"
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"
@renatoargh
renatoargh / look-ahead.js
Created February 14, 2018 03:42
look ahead
var regexp = /^\[(.*?(?=\]))\]/;
@renatoargh
renatoargh / RunAProxyOnAmazonEC2VPC.md
Created January 28, 2018 23:38 — forked from webinista/RunAProxyOnAmazonEC2VPC.md
Create a proxy server on an Amazon EC2 (VPC) instance

This will create a proxy server in whatever your availability zone your VPC is in. For me, that's us-east-1b. For you, that may be something different. Steps 10+ should more or less work regardless of your provider since those steps cover the setup and configuration of TinyProxy.

  1. Click the Launch Instance button.
  2. Choose Ubuntu Server 14.04 LTS (HVM), SSD Volume Type. This isn't strictly necessary. If you choose another OS, check its documentation for how to install new packages.
  3. On the Choose an Instance Type screen, select t2.micro. It's Free Tier eligible.
  4. Click the Next: ... buttons until you reach the Configure Security Group screen.
    • You may wish to reduce the amount of storage on the Add Storage screen. This is optional.
    • You may wish to add a tag on the Tag Instance screen. This is also optional.
  5. On the Configure Security Group screen:
  • Select Create a new security group.
@renatoargh
renatoargh / gist:93702bdafbd19d17b7bad5bfe755d9c5
Created January 28, 2018 17:25 — forked from aws-scripting-guy/gist:884ffa9d44bd14f7493a670543284552
AWS EC2 metadata. Check attached IAM role from EC2 instance. Get temporary credentials.
# Get IAM Role name from Instance Profile Id
curl http://169.254.169.254/latest/meta-data/iam/info
# Get credentials
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<role-name>
# More info
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
@renatoargh
renatoargh / gist:913374310b846ec670e011c44108115e
Created January 28, 2018 13:42 — forked from aioutecism/gist:2638bb9eaf9ffc13348c
Set up a VPN Server (PPTP) on AWS and use it anywhere

Set up a VPN Server (PPTP) on AWS

  1. Create a EC2 instance using Ubuntu 14.04.
  2. In Secure Group Inbound Rules, add a SSH Rule(TCP, Port 22, 0.0.0.0/0) and a Custom TCP Rule(TCP, Port 1723, 0.0.0.0/0).
  3. Optional: Associate a Elastic IP with the instance.
  4. SSH into the instance.
  5. sudo apt-get install pptpd.
  6. sudo vim /etc/pptpd.conf. Uncomment localip 192.168.0.1 and remoteip 192.168.0.234-238,192.168.0.245.
  7. sudo vim /etc/ppp/pptpd-options. Uncomment ms-dns and ms-wins. Change the IP to Google's DNS like this:
const {
name,
favoriteColor = 'red'
} = user
@renatoargh
renatoargh / ws.js
Created January 5, 2018 18:39
Teste
swd
const path = require('path')
const fs = require('fs')
const Sequelize = require('sequelize')
const { CONNECTION_STRING } = process.env
const modelsFolder = path.join(__dirname, '../models')
const models = {}
module.exports = () => {
// 1. Initialisation code
const express = require('express')
const sequelizeMiddleware = require('./middlewares/sequelize')
const authMiddleware = require('./middlewares/auth')
const app = express()
app.use(sequelizeMiddleware()) // 1. Sequelize startup
app.use(authMiddleware) // 2. Auth and schema management
app.get('/tasks', async (req, res, next) => {
// 3. Here we must query the database and
@renatoargh
renatoargh / gettasks.js
Last active January 10, 2018 01:05
Example code for data isolation with node.js, express and sequelize
/* gettasks.js */
app.get('/tasks', async (req, res, next) => {
const { user } = req
const { Task, TaskType } = req.models
try {
const tasks = await Task.findAll({
where: { userId: user.id },
include: {