Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / isolateKeys.js
Last active January 9, 2018 21:08
Immutable removal of keys from a javascript object using ES6 deconstructing.
//Avoid annoying immutability bugs by using this nice ES6 deconstructing trick to keep your object immutable.
// example obj
const someObj = {
want: 'this',
need: 'that',
dont: 'wantthis',
forget: 'this'
};
@wichopy
wichopy / Jenkinsfile.groovy
Created November 20, 2017 00:53 — forked from Faheetah/Jenkinsfile.groovy
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'No quotes in single backticks'
sh 'echo $BUILD_NUMBER'
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"'
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"'
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"'
echo 'Using three backslashes still results in preserving the single quotes'
@wichopy
wichopy / checkbox_extract_script.bas
Created March 19, 2017 15:28
Script to extract data from excel checkboxes.
Sub CheckboxLoop()
'Using this as a start:
'PURPOSE: Loop through each Form Control Checkbox on the ActiveSheet
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim cb As Shape
Dim i As Integer