Skip to content

Instantly share code, notes, and snippets.

View joshbedo's full-sized avatar
🤙

Josh Bedo joshbedo

🤙
View GitHub Profile
@joshbedo
joshbedo / proxy.js
Created December 19, 2015 08:22
Docker proxy
//var GUEST_URL = process.env['DOCKER_HOST'].substring(0, guestPortIndex);
console.log(proxy.createServer({
target : 'http://192.168.99.100',
ws: true
}).listen(2376));
@joshbedo
joshbedo / 1-react-native-simulator-and-device.md
Created December 18, 2015 06:08 — forked from almost/1-react-native-simulator-and-device.md
Test React Native on the simulator and on a device without editing the code each time!

In the default React Native app scaffolding you have to edit AppDelegate.m to change where it loads the code if you want to test on your device. I use the following snippet to detect if it's being compiled for Debug or Production and for the Simulator or a device. For Production it uses a copy of the code included in the bundle, for Debug on the simualtor it loads from a server on localhost and for Debug on a device it loads from a server on a given IP address.

NOTE: You need to edit YOUR-IP-HERE and change it to the IP to load the code from when in Debug mode on a device. You could use a service like ngrok to make this work from anywhere.

  NSURL *jsCodeLocation;

  // Loading JavaScript code
  #if DEBUG
    // For Debug build load from development server. Start the server from the repository root:
@joshbedo
joshbedo / sailsjs_nginx
Created August 17, 2015 14:12
Nginx config for Node.js and Websockets
# Load balancer configuration
upstream exampleApp {
# Directs to the process with least number of connections.
least_conn;
# One failed response will take a server out of circulation for 20 seconds.
server 127.0.0.1:10080 fail_timeout=20s;
#server 127.0.0.1:10081 fail_timeout=20s;
#server 127.0.0.1:10082 fail_timeout=20s;
#server 127.0.0.1:10083 fail_timeout=20s;
@joshbedo
joshbedo / s3multipart.js
Created August 13, 2015 11:57
S3 multipart upload with NodeJS
var express = require('express')
var app = express()
var AWS = require('aws-sdk');
var bodyParser = require('body-parser');
var fs = require('fs');
var zlib = require('zlib'); // gzip compression
var multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty();
@joshbedo
joshbedo / gist:743f090f6b939725572b
Last active August 29, 2015 14:24
Queues (FIFO) and Stacks (LIFO)
class Node {
constructor(data) {
this.data = data;
this.previous = null;
}
}
class Stack {
constructor() {
this.top = null;
var list = [1,4,8,10,23,26,55,77,88];
var binarySearch = function(key) {
var low = 0;
var high = list.length - 1;
while(low <= high) {
var mid = Math.floor(low + (high - low) / 2);
if (key < list[mid]) {
@joshbedo
joshbedo / gist:5ae51fff0b9377090a26
Created July 9, 2015 13:42
3 Sum problem - Given N integers how many triples sum to exactly zero
var numbers = [20,-20, 0, 50, -50, 0];
var len = numbers.length;
var count = 0;
var threeSum = function() {
for(var i = 0;i < len; i++) {
for(var j = i + 1;j < len; j++) {
for(var k = j + 1;k < len; k++) {
if (numbers[i] + numbers[j] + numbers[k] == 0) {
if @state.isReady
D.ul { className: 'list-table-body clearfix'}, [
[
_.map(exportResults, (file_export, index) =>
D.ul { className: 'list-table-row with-action' }, [
D.li { className: 'filename' }, file_export.file_name
D.li { className: 'export-progress' }, [
@streamProgressBar(file_export)
]
if @inProgress(file_export)
@joshbedo
joshbedo / gist:64dc4f60d1d97ba6c332
Created March 20, 2015 15:30
long-polling React
@ProgressBar = ProgressBar({ pending: file_export.completed_items, total: file_export.total_items })
if @inProgress(file_export)
do poll = () =>
setTimeout (=>
debugger
$.ajax(
url: '/api/v1/file_exports.json',
success: (data) =>
@ProgressBar.setState({ pending: data.completed_items })
@joshbedo
joshbedo / tabs
Created March 6, 2015 15:21
tabs
import React from 'react';
const D = React.DOM
var Tabs = React.createClass({
displayName: 'Tabs',
propTypes: {
tabActive: React.PropTypes.number,
onMount: React.PropTypes.func,
onBeforeChange: React.PropTypes.func,
onAfterChange: React.PropTypes.func,