Skip to content

Instantly share code, notes, and snippets.

@wichopy
wichopy / filterString.js
Created February 3, 2018 03:01
Filter out text strings using regex of a URL.
// assuming env var
// BASE_URL=www.mydomain.com
removebaseURL = (fullURL) => { // pass in (www.mydomain.com/kittens)
// Allow api calls to handle just the end point (/kittens) or the full URL (www.mydomain.com/kittens)
// by filtering out the base URL if the route contains it.
const reg = new RegExp(process.env.BASE_URL, 'gi');
const match = fullURL.match(r eg)
let endpoint
if (match) {
endpoint = fullURL.split(reg)[1]
@wichopy
wichopy / redeploy.sh
Created May 1, 2018 00:53
Redeploy server war and restart postgres docker container locally.
#!/bin/bash
echo "Stop tomcat";
/Library/Tomcat/bin/shutdown.sh;
echo "Restart postgres container";
#Assuming you have docker, with a postgres container running called local-postgres. The postgres container can be renamed in the docker run command.
docker stop local-postgres;
docker rm local-postgres;
docker run --name local-postgres -e POSTGRES_USER=user -e POSTGRES_DB=db -d -p 5432:5432 postgres;
@wichopy
wichopy / pm2_with_env.sh
Created July 1, 2018 14:17
PM2 start npm script with environment variables injected.
pm2 start npm --name [process name] -- run [npm script name] ENV_VAR=some_env_var_value
@wichopy
wichopy / webpack-docker-package-conf.json
Created July 12, 2018 02:38
Connecting webpack dev server to an api hosted locally in a docker container
"proxy": {
"/server": {
"target": "http://0.0.0.0:8080",
"changeOrigin": true
}
}
@wichopy
wichopy / cors-notes.md
Last active July 23, 2018 03:24
CORS requests

resource: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#The_HTTP_request_headers

  • web applications makes a CORs request when it requests a resource that has a different origin (domain, protocol, port) then its own origin.
  • CORS is for security reasons, browsers restrict cross-origin HTTP requests initiated within scripts
  • HTTP Header that allows servers to describe the set of origins that are permitted to read that information using a web browser.
  • HTTP requests that can cause side-effects on server's data, browser must pre-flight the request (HTTP OPTIONS method), After approval, the server will send the actual request back to the browser.
  • Allowed Methods:
    • GET
    • HEAD
  • POST
@wichopy
wichopy / higher_order_single_click.js
Last active August 16, 2018 01:24
higher order single click function
//Wrap an onclick handler
const once = fn => {
let done = false;
return (...args) => {
if (!done) {
done = true;
fn(...args);
}
}
}
@wichopy
wichopy / google-login.js
Created April 15, 2019 21:22
Firebase Auth
var provider = new firebase.auth.GoogleAuthProvider();
function onSigninClick () {
firebase.auth().signInWithPopup(provider).then(function (result) {
console.log('Auth resposne from firebase:', result)
})
}
function onSignoutClick () {
firebase.auth().signOut().then(function() {
@wichopy
wichopy / gist:315c76626dd405340de3cd3aefb66310
Created July 31, 2019 03:51
brew installing my trace route (MTR) and manually sym linking
# Brew cannot sym link this app on its own due to permissions, this is how to do it manually:
brew install mtr
# brew link mtr // will return error
# sudo brew link mtr // will return warning about how its dangerous to run brew in sudo
# Manually sym link the path to your mtr install to your local bin folder.
# Check the version by going to /usr/local/Cellar/mtr

Keybase proof

I hereby claim:

  • I am wichopy on github.
  • I am wichopy (https://keybase.io/wichopy) on keybase.
  • I have a public key whose fingerprint is 7658 0331 4DB7 C2E0 833A 44FD 5BAC 3985 7ECF C68B

To claim this, I am signing this object:

@wichopy
wichopy / main.yml
Created November 21, 2019 00:48
Github action to deploy to a google storage bucket.
name: DEPLOY-ON-PUSH
on: [push]
jobs:
deploy:
name: Deploy new build
runs-on: ubuntu-latest
steps: