Skip to content

Instantly share code, notes, and snippets.

View lancevo's full-sized avatar

Lance Vo lancevo

View GitHub Profile
@lancevo
lancevo / letsencrypt.md
Created June 2, 2021 17:09
Set up letsencrypt with nginx and node
@lancevo
lancevo / mysql-docker.sh
Created September 26, 2019 21:45 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@lancevo
lancevo / filterarrayinplace.js
Created August 13, 2019 14:12
Filter array in place
function filterInPlace(array, condition) {
let iOut = 0;
for (let i = 0; i < array.length; i++) {
if (condition(array[i])) {
array[iOut++] = array[i];
}
}
array.length = iOut;
}
@lancevo
lancevo / README.md
Created June 3, 2019 19:23 — forked from egucciar/README.md
Shadow Dom Commands

ShadowDom

Quick Start

In the index.js or the root file of your cypress/support folder,

@lancevo
lancevo / generate_mac.bash
Created May 20, 2019 18:03
change MAC address on Mac
function changeMac() {
local mac=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
sudo ifconfig en0 ether $mac
sudo ifconfig en0 down
sudo ifconfig en0 up
echo "Your new physical address is $mac"
}
@lancevo
lancevo / README.md
Created January 24, 2019 05:19
Sort Objects

Objects Sorter:

Sort objects by property name. It detects property type such as number, string, and date and sort them properly.

Usage

var models = [
@lancevo
lancevo / getQuery.js
Created January 21, 2019 15:29
extracts and parses url query string
(function(window){
'use strict';
function getQuery(query){
var args = decodeURIComponent(location.search).substring(1).split('&');
var argsParsed = {};
var i, arg, kvp, key, value;
for (i=0; i < args.length; i++) {
arg = args[i];
if (-1 === arg.indexOf('=')) {
argsParsed[decodeURIComponent(arg).trim()] = true;
@lancevo
lancevo / nginxproxy.md
Created January 15, 2019 20:44 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@lancevo
lancevo / atob.js
Created December 14, 2018 03:29 — forked from jmshal/atob.js
Node.js ponyfill for atob and btoa encoding functions
module.exports = function atob(a) {
return new Buffer(a, 'base64').toString('binary');
};
@lancevo
lancevo / common-regex-patterns.js
Last active November 1, 2018 13:23
Some of the common regex patterns
// Separate numbers to a group of 3 and add a comma
'123456'.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); // output: 123,456