Skip to content

Instantly share code, notes, and snippets.

@AlexandroPerez
AlexandroPerez / site.conf
Created March 24, 2017 03:43
nginx configuration file for a nodejs app listening on port 3030
server {
listen 8080;
server_name localhost;
location / {
root /var/www/local.com;
index index.html index.htm;
}
location /api {
.element {
-webkit-user-select: none;
-moz-user-select: -moz-none;
/*IE10*/
-ms-user-select: none;
user-select: none;
/*You just need this if you are only concerned with android and not desktop browsers.*/
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
@AlexandroPerez
AlexandroPerez / nginx_provision.sh
Last active June 28, 2017 07:44
Vagrant provision for installing nginx in Ubuntu Xenial
echo "Adding nginx deb and deb-src packages to /etc/apt/sources.list"
echo "deb http://nginx.org/packages/ubuntu/ xenial nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/ubuntu/ xenial nginx" >> /etc/apt/sources.list
echo "Downloading nginx_signing.key..."
curl -Os https://nginx.org/keys/nginx_signing.key
echo "Adding it to the apt program keyring"
apt-key add ./nginx_signing.key
echo "Installing nginx..."
@AlexandroPerez
AlexandroPerez / nginx_postgresql_provision.sh
Created June 28, 2017 08:07
Vagrant provision for installing latest stable nginx and postgresql 9.6 in Ubuntu Xenial (16.04)
echo "Adding nginx deb and deb-src packages to /etc/apt/sources.list"
echo "deb http://nginx.org/packages/ubuntu/ xenial nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/ubuntu/ xenial nginx" >> /etc/apt/sources.list
echo "Downloading nginx_signing.key..."
curl -Os https://nginx.org/keys/nginx_signing.key
echo "Adding it to the apt program keyring"
apt-key add ./nginx_signing.key
echo "Adding postgresql deb packages..."
@AlexandroPerez
AlexandroPerez / memory-optimization#using-hashes-to-abstract-a-very-memory-efficient-plain-key-value-store-on-top-of-redis.md
Last active January 14, 2020 03:38
Explaining the code: Using hashes to abstract a very memory efficient plain key-value store on top of Redis
myPromise.then(function() {
// Some error may happen
throw('An exception that would be caught');
}).catch(function() {
console.log('error');
});
// Is the same as this, the errHandle tries to catch any unhandled error
// from previous result.
myPromise.then(func, null).then(null, errHandle);
@AlexandroPerez
AlexandroPerez / nginx_node_provision.sh
Created March 11, 2018 11:55
Script for installing latest nginx and node LTS. Can be used as a Vagrant provision script, or as a Google Cloud Startup Script
echo "Adding nginx deb and deb-src packages to /etc/apt/sources.list"
echo "deb http://nginx.org/packages/ubuntu/ xenial nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/ubuntu/ xenial nginx" >> /etc/apt/sources.list
echo "Downloading nginx_signing.key..."
curl -Os https://nginx.org/keys/nginx_signing.key
echo "Adding it to the apt program keyring"
apt-key add ./nginx_signing.key
echo "Installing nginx..."
@AlexandroPerez
AlexandroPerez / rsync_inotifywait_cigwin_-_host_to_vagrant_box.md
Last active March 14, 2018 14:45
Sync from windows host to vagrant box using cygwin, rsync and inotifywait

Requirements

You need to have cygwin and its following packages installed

  • make (Devel group -> make)
  • rsync (Net group -> rsync)
  • ssh (Net group -> openSSH)

NOTE: You may already have ssh installed due to git shell, or other shell installation, but make sure you install the cygwin version of ssh (openSSH)

@AlexandroPerez
AlexandroPerez / autosync.sh
Last active July 14, 2020 03:55
Auto Sync shell script for Cygwin. For requirements see: https://gist.github.com/AlexandroPerez/c6122b1f8648273f83b894e5c4436e6a
#!/bin/bash
# This script is meant to run in cygwin as a way to sync a Windows host to a Guest Vagrant Machine
# So you can edit your code in the host, sync changes to your vagrant machine, and let node/npm
# run in a local folder (no more symlink problems!)
#
# For requirements see: https://gist.github.com/AlexandroPerez/c6122b1f8648273f83b894e5c4436e6a
#
# Usage: autosync.sh user@host:/path/to/remote/folder
#
# Optional but recommended: add a .syncignore file to your folder, and add
@AlexandroPerez
AlexandroPerez / .bashrc
Last active June 15, 2018 08:59
Cygwin and WSL colored bash prompt that shows current git branch if the folder is a git repo.
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
# NOTE: The dollar sign ($) has to be escaped so that the above function is executed every time the prompt is shown
# like this: \$(git_branch)
export PS1="\[\e]0;\w\a\]\n\[\e[36m\]CygWin:\[\e[33m\]\w\[\e[0m\] \[\e[32m\]\[\e[1m\]\$(git_branch)\[\e[0m\]\n$ "
# For WSL
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'