Skip to content

Instantly share code, notes, and snippets.

View stephencweiss's full-sized avatar
🎉

Stephen Weiss stephencweiss

🎉
View GitHub Profile
@stephencweiss
stephencweiss / React - .bind()
Last active December 10, 2018 15:02
Binding methods in React supplies the appropriate context so that a function can be passed around.
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
}
this.searchDB = this.searchDB.bind(this);
this.handleClick = this.handleClick.bind(this); // This was the missing critical line
}
handleClick (type, param) {
@stephencweiss
stephencweiss / package.json webpack scripts
Created December 10, 2018 14:35
Scripts to run with your project that will bundle according to the development and production configurations.
//package.json
...
"scripts": {
...
"bundle:dev": "webpack --watch --debug --mode='development'",
"bundle:prod": "webpack --watch --mode='production'",
}
...
@stephencweiss
stephencweiss / webpack.config.js - Custom Mode
Last active December 10, 2018 14:40
Template for customizing the webpack config file for modes development and production
//webpack.config.js
const path = require('path');
const SRC_DIR = path.resolve(__dirname, 'client')
const DIST_DIR = path.resolve(__dirname, 'public')
var config = {
entry: `${SRC_DIR}/index.jsx`,
output: {
filename: 'bundle.js',
path: DIST_DIR
@stephencweiss
stephencweiss / git remote -v
Created December 9, 2018 21:53
A git remote response with multiple remotes
$ git remote -v
origin https://github.com/myUser/example.git (fetch)
origin https://github.com/myUser/example.git (push)
upstream https://github.com/someoneElse/example.git (fetch)
upstream https://github.com/someoneElse/example.git (push)
@stephencweiss
stephencweiss / Standard fs.readfile & fs.createReadStream
Last active December 8, 2018 15:29
Examples of using Node's fs to read a file from disk.
//NB: assumes encoding is 'utf8'; adjust as necessary
const readFromDiskAsync = (file) => {
fs.readFile(file, { encoding:'utf8'}, function read(err, data) {
if (err) {throw err;}
console.log('The data is --> ', data)
})
}
const readFromDiskStream = (file) => {
0001 // x
0100 // y
----
0101
0001 // x
0101 // y
----
0100
0100 // x
0101 // y
----
0001
@stephencweiss
stephencweiss / Bitwise swap
Created November 30, 2018 17:43
A bitwise swap function in Javascript - performing in place swap and constant space
var bitwiseSwap = (x,y) => {
if (x === y) {
return;
} else {
x = x ^ y;
y = x ^ y;
x = x ^ y;
}
}
@stephencweiss
stephencweiss / Standard swap
Created November 30, 2018 17:42
A standard swap function in Javascript
let swap = (i, j) => {
let temp = i;
i = j;
j = temp
}