Skip to content

Instantly share code, notes, and snippets.

View sdesalas's full-sized avatar
💻

Steven de Salas sdesalas

💻
View GitHub Profile
const http = require('http');
var attempts = 30, complete = 0, delay = 100,
url = 'http://domain.com/path/to/entrypoint';
Array(attempts)
.fill(0)
.forEach((value, index, arr) => setTimeout(() => {
var start = new Date().getTime();
http.get(url, function(response) {
@sdesalas
sdesalas / Observable.js
Last active April 25, 2017 06:20
Simple Observable (EventEmitter) class example.
//
// Observable.js
//
// Simple JavaScript observable class to inherit from.
// Allows for event subscription using .on('event')
//
// Example:
//
// let weather = new Observable();
// weather.on('rain', () => person1.wearGumboots());
@sdesalas
sdesalas / git.log.sh
Last active May 1, 2017 13:25
git log pretty format
# output 10 lines
git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --date=short -10 | cat -
# copy 10 lines to env variable
export GIT_LOG=$(git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --date=short -10 | cat -)
# windows (needs testing)
for /f %%i in ('git log --date=short -10') do set GIT_LOG=%%i
@sdesalas
sdesalas / handler.js
Created May 28, 2017 13:44 — forked from jeffrafter/handler.js
Simple HTTP Server and Router in node.js
exports.createHandler = function (method) {
return new Handler(method);
}
Handler = function(method) {
this.process = function(req, res) {
params = null;
return method.apply(this, [req, res, params]);
}
}
@sdesalas
sdesalas / Terraform-Blue-Green-AWS.md
Created June 21, 2017 06:54 — forked from ryan0x44/Terraform-Blue-Green-AWS.md
Blue-Green AWS Auto Scaling Deployments with Terraform

A quick note on how I'm currently handling Blue/Green or A/B deployments with Terraform and AWS EC2 Auto Scaling.

In my particular use case, I want to be able to inspect an AMI deployment manually before disabling the previous deployment.

Hopefully someone finds this useful, and if you have and feedback please leave a comment or email me.

Overview

I build my AMI's using Packer and Ansible.

@sdesalas
sdesalas / readme.md
Created July 18, 2017 15:12 — forked from jobsamuel/readme.md
Run NodeJS as a Service on Ubuntu 14.04 LTS

Run NodeJS as a Service on Ubuntu 14.04 LTS

With Node you can write very fast JavaScript programs serverside. It's pretty easy to install Node, code your program, and run it. But > how do you make it run nicely in the background like a true server?

  • Go to /etc/init/
  • $ sudo vim yourapp.conf
  • Paste script.conf
  • $ sudo start yourapp
  • And when you wanna kill the process $ sudo stop yourapp
@sdesalas
sdesalas / rc.local
Created July 19, 2017 14:21
/etc/rc.local (USBMON)
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
@sdesalas
sdesalas / HttpHelper.java
Created November 13, 2018 21:17
Android HttpHelper class extends AsyncTask<String, String, String>
package com.domain.myApp;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.InputStream;
@sdesalas
sdesalas / base56.js
Last active November 15, 2018 20:59
Base56 random character generation.
// Thanks to https://github.com/evanx/secret-base56
const letters24 = 'ABCDEFGHJKLMNPQRSTUVWXYZ'; // exclude I and O since too similar to 0 and 1
const digits8 = '23456789'; // omit 0 and 1 to avoid potential confusion with O and I (and perhaps 'l')
const charset = [digits8, letters24, letters24.toLowerCase()].join('');
module.exports = length => Array(length)
.fill()
.map(() => charset[Math.floor(Math.random() * 56)])
.join('');
@sdesalas
sdesalas / JNI.cpp
Created November 24, 2018 13:31 — forked from Nimrodda/JNI.cpp
Raw JNI with async callbacks
static jclass callbacksClass;
static jobject callbacksInstance;
JNIEXPORT void JNICALL Java_com_example_NativeClass_nativeMethod(JNIEnv* env, jclass callingObject, jobject callbacks)
{
// Cache the Java callbacks instance
callbacksInstance = env->NewGlobalRef(callbacks);
// Cache the Java callbacks class (in case of interface, this will be the concrete implementation class)
jclass objClass = env->GetObjectClass(callbacks);