Skip to content

Instantly share code, notes, and snippets.

View patbonecrusher's full-sized avatar
:octocat:

Patrick Laplante patbonecrusher

:octocat:
View GitHub Profile
@patbonecrusher
patbonecrusher / Free O'Reilly Books.md
Created December 19, 2017 03:36 — forked from augbog/Free O'Reilly Books.md
Free O'Reilly Books

Free O'Reilly books and convenient script to just download them.

Thanks /u/FallenAege/ and /u/ShPavel/ from this Reddit post

How to use:

  1. Take the download.sh file and put it into a directory where you want the files to be saved.
  2. cd into the directory and make sure that it has executable permissions (chmod +x download.sh should do it)
  3. Run ./download.sh and wee there it goes. Also if you do not want all the files, just simply comment the ones you do not want.
@patbonecrusher
patbonecrusher / rabbitmq.txt
Created December 13, 2017 21:07 — forked from sdieunidou/rabbitmq.txt
create admin user on rabbitmq
rabbitmqctl add_user test test
rabbitmqctl set_user_tags test administrator
rabbitmqctl set_permissions -p / test ".*" ".*" ".*"

Set Up Babel — Working Example

We need alpha 7 version from Babel.

npm install --save-dev [email protected]
npm install --save-dev babel-plugin-transform-optional-chaining@^7.0.0-alpha.13.1

Create a .babelrc file in the project root:

// paste this before your require child_process at the beginning of your main index file.
(function() {
var childProcess = require("child_process");
var oldSpawn = childProcess.spawn;
function mySpawn() {
console.log('spawn called');
console.log(arguments);
var result = oldSpawn.apply(this, arguments);
return result;
if (!('path' in Event.prototype)) {
Object.defineProperty(Event.prototype, 'path', {
get: function () {
const path = [];
let currentElem = this.target;
while (currentElem) {
path.push(currentElem);
currentElem = currentElem.parentElement;
}
if (path.indexOf(window) === -1 && path.indexOf(document) === -1)
process.stdin.resume();//so the program will not close instantly
function exitHandler(options, err) {
if (options.cleanup) console.log('clean');
if (err) console.log(err.stack);
if (options.exit) process.exit();
}
//do something when app is closing
process.on('exit', exitHandler.bind(null,{cleanup:true}));
@patbonecrusher
patbonecrusher / async-examples.js
Created September 27, 2017 00:41 — forked from developit/async-examples.js
Async Array utilities in async/await. Now available as an npm package: https://github.com/developit/asyncro
/** Async version of Array.prototype.reduce()
* await reduce(['/foo', '/bar', '/baz'], async (acc, v) => {
* acc[v] = await (await fetch(v)).json();
* return acc;
* }, {});
*/
export async function reduce(arr, fn, val, pure) {
for (let i=0; i<arr.length; i++) {
let v = await fn(val, arr[i], i, arr);
if (pure!==false) val = v;
@patbonecrusher
patbonecrusher / image2base64.js
Created September 13, 2017 17:57 — forked from jfsiii/image2base64.js
Convert a remote image to Base64-encoded string
// Uses [request](https://github.com/mikeal/request)
// /?url=http://nodejs.org/logo.png
// /?uri=http://nodejs.org/logo.png
// /?url=http://nodejs.org/logo.png&cb=cbName
// /?url=http://nodejs.org/logo.png&callback=cbName
var fs = require('fs');
var url = require('url');
var http = require('http');
var request = require('request');
@patbonecrusher
patbonecrusher / cheatsheet.cpp
Created August 26, 2017 22:01 — forked from satwikkansal/cheatsheet.cpp
C++ STL cheatsheet for competitive progrmming
/*
This a header file that includes every standard library.
You can use it to save time.
NOTE: This header file may not be recognized by compilers
other than gcc.
*/
#include <bits/stdc++.h>
/*
//Use this if the above header file doesn't work.
@patbonecrusher
patbonecrusher / react-router
Created June 16, 2017 02:28
This allows proper refreshing of browser page while running in dev mode with webpack.
// The keyword Switch is extremely important. Without it, the NotFoundPage
// becomes visible on all other pages.
class App extends Component {
render () {
return (
<div id='app' className='phs-app'>
<Header id="toolbar"/>
<NavigationBar />
<div id='content'>