Skip to content

Instantly share code, notes, and snippets.

View BerkeleyTrue's full-sized avatar
💭
Baby Yoda is my spirit animal

Berkeley Martinez BerkeleyTrue

💭
Baby Yoda is my spirit animal
View GitHub Profile
var fs = require('fs');
var emailName = process.argv[2];
var percent = process.argv[3];
var emails = require('./' + emailName + '.json');
var newEmails = emails.slice((emails.length * (percent / 100)));
console.log(
'Do emails end the same? %s',
emails[emails.length - 1] === newEmails[newEmails.length -1]
);
// add the custom static method to the Loopback User model
// note the dollar sign here indicatest to the user this function
// returns an Observable
User.getPointsById$ = function getPointsById$(id) {
return Observable.create(observer => {
let isDisposed = false;
// Here we tap into mongodb method
// safe ObjectID creation
// MongoID(id: ObjectID|String) => ObjectID
// MongoDB requires id's to be of type ObjectID
@BerkeleyTrue
BerkeleyTrue / deserializer.js
Last active April 13, 2016 05:14
Free Code Camp's new deserializer
const fields = {
progressTimestamps: false,
completedChallenges: false,
challengeMap: false
};
passport.deserializeUser((id, done) => {
// We use a combineLatest here to run both of these
// database request in parallel
Observable.combineLatest(
// `findById$` notice the dolar sign?
@BerkeleyTrue
BerkeleyTrue / deserializer.js
Last active April 13, 2016 00:37
Loopback's default deserialization
passport.deserializeUser(function(id, done) {
// DB query 1:
// Find the user in the database
// This is where the largest amount of data is sent
// back form the database
self.userModel.findById(id, function(err, user) {
if (err || !user) {
return done(err, user);
}
// DB query 2:
@BerkeleyTrue
BerkeleyTrue / restart_bluetooth.sh
Created April 9, 2016 18:30 — forked from nicolasembleton/restart_bluetooth.sh
Restart Bluetooth Daemon on Mac OS X without restarting
#!/bin/bash
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport

You'll need node, npm, and bower installed globaly. As well as MongoDB set up and all the .env keys set up according to the contributing guidlines

I'd also recommend using node 4.x LTS which is what we use on our servers but I've heard it runs fine using node 5

  • NODE_ENV=development npm install
  • bower install
  • npm run once
  • npm run build
function completedChallenge(req, res, next) {
// build user update data, no longer mutates user object
const { updateData, alreadyCompleted, points } = buildUpdateData(req);
// calls an update data using user instance id and sends only updateData
return user.update$(updateData)
.subscribe(
count => log('%s documents updated', count),
next,
function() {
return res.json({
function completedChallenge(req, res, next) {
const { user, body } = req;
// mutates user object
const { alreadyCompleted } = updateUserProgress(user, body);
/ sends entire user object to database
return saveUser(req.user)
.subscribe(
() => {},
next,
function() {

SHPE Meeting of the minds

January 16, 2016

Start time: 11:21AM

End time:

What do you expect out of this retreat?

Reynolds

@BerkeleyTrue
BerkeleyTrue / ipMap.sh
Last active July 20, 2017 23:09
Redirect a url to a localhost port
# First we need to map our localhost + port combo to another ip. You'll need root priviliges for this
sudo ifconfig lo0 10.0.0.1 alias && \
echo "rdr pass on lo0 inet proto tcp from any to 10.0.0.1 port 80 -> 127.0.0.1 port 3000" | sudo pfctl -ef -
# Now edit /etc/hosts
sudo vim /etc/hosts
# and add the following to the list
# NOTE: Do not edit anthing on this list you did not add
10.0.0.1 mydomain.dev
10.0.0.1 www.mydomain.dev
# I choose to use a .dev TLD as these are never going to conflict seeing how google has bought these TLD's