Skip to content

Instantly share code, notes, and snippets.

View behrad's full-sized avatar
🤠
Doing Well

Behrad Zari behrad

🤠
Doing Well
View GitHub Profile
package com.emil.android.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/**
* Check device's network connectivity and speed
* @author emil http://stackoverflow.com/users/220710/emil
#!/usr/bin/env bash
#
# An example init script for running a Node.js process as a service
# using Strongloop's slc as the process monitor. For more configuration options
# associated with slc, see: http://docs.strongloop.com/display/public/SLC/slc+run.
# This script assumes you've installed slc globally with `npm install -g strongloop`.
#
# You will need to set the environment variables noted below to conform to
# your use case, and change the init info comment block.
#
var cluster = require('cluster');
if(cluster.isMaster) {
cluster.fork()
.on('online', function() {
this.disconnect();
});
} else {
process.on('internalMessage', function(msg) {
console.log('internalMsg', msg);
@behrad
behrad / forever-initd
Last active August 29, 2015 14:07
forever init script
#!/bin/bash
#
# An init.d script for running a Node.js process as a service using Forever as
# the process monitor. For more configuration options associated with Forever,
# see: https://github.com/nodejitsu/forever
#
# This was written for Debian distributions such as Ubuntu, but should still
# work on RedHat, Fedora, or other RPM-based distributions, since none of the
# built-in service functions are used. So information is provided for both.
#
/*
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js
*/
var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = 'video.mp4';

##The Good, The Bad, & The Ugly Ways of handling Async Operations With Javascript## #####Callbacks < Promises < Generators#####


###An Example: 5 in-sequence Async Operations### (also see parallel-sequence example: https://gist.github.com/willrstern/af3a3308fc5864cf48f8)
###The Ugly Way: Callbacks### After each function takes place, handle any errors & do the next thing - It's easy to walk through the code and understand what's going on...but it's ugly as sin
@behrad
behrad / npm-deps
Created January 28, 2014 08:46
Npm Dependencies
​#!/bin/sh
for i in $(find ./local_modules -type d -maxdepth 1) ; do
packageJson="${i}/package.json"
if [ -f "${packageJso​​n}" ]; then
echo "installing ${i}..."
npm install "${i}"
fi
done
@behrad
behrad / chained-async-call
Created January 27, 2014 14:27
Simple utility to run and collect multiple async functions callbacks
/**
* Data fetching helper.
*/
function get(obj) {
var pending = 0
, res = {}
, callback
, done;
-module(date_util).
-compile(export_all).
epoch() ->
now_to_seconds(now())
.
epoch_hires() ->
now_to_seconds_hires(now())
.
@behrad
behrad / myapp.conf
Created October 13, 2013 07:56 — forked from bsphere/myapp.conf
check host localhost with address 127.0.0.1
start "/sbin/start myapp"
stop "/sbin/stop myapp"
if failed port 3000 protocol HTTP
request /
with timeout 5 seconds
then restart