Skip to content

Instantly share code, notes, and snippets.

Will C. wichopy

Block or report user

Report or block wichopy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View google-login.js
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 Aug 16, 2018
higher order single click function
View higher_order_single_click.js
//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 Jul 23, 2018
CORS requests
View cors-notes.md

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 Jul 12, 2018
Connecting webpack dev server to an api hosted locally in a docker container
View webpack-docker-package-conf.json
"proxy": {
"/server": {
"target": "http://0.0.0.0:8080",
"changeOrigin": true
}
}
@wichopy
wichopy / pm2_with_env.sh
Created Jul 1, 2018
PM2 start npm script with environment variables injected.
View pm2_with_env.sh
pm2 start npm --name [process name] -- run [npm script name] ENV_VAR=some_env_var_value
@wichopy
wichopy / redeploy.sh
Created May 1, 2018
Redeploy server war and restart postgres docker container locally.
View redeploy.sh
#!/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 Feb 3, 2018
Filter out text strings using regex of a URL.
View filterString.js
// 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 Jan 9, 2018
Immutable removal of keys from a javascript object using ES6 deconstructing.
View isolateKeys.js
//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 Nov 20, 2017 — forked from Faheetah/Jenkinsfile.groovy
Jenkinsfile idiosynchrasies with escaping and quotes
View Jenkinsfile.groovy
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 Mar 19, 2017
Script to extract data from excel checkboxes.
View checkbox_extract_script.bas
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
You can’t perform that action at this time.