Skip to content

Instantly share code, notes, and snippets.

View pdeschen's full-sized avatar

Pascal Deschênes pdeschen

  • Montréal, Canada
View GitHub Profile
@pdeschen
pdeschen / gist:983569
Created May 20, 2011 19:15
Ajax jQuery Authentication Request
$.ajax( {
url : '/model/user.json',
dataType : 'json',
beforeSend : function(xhr) {
var bytes = Crypto.charenc.Binary.stringToBytes(username + ":" + password);
var base64 = Crypto.util.bytesToBase64(bytes);
xhr.setRequestHeader("Authorization", "Basic " + base64);
},
error : function(xhr, ajaxOptions, thrownError) {
reset();
@pdeschen
pdeschen / initd
Created May 12, 2013 18:10
CentOS service initd erb template. Ready to use in Opscode Chef or replace template variables with your own hard-coded value. Takes into account priority/nice, sudo user, and /etc/sysconfig/ Support start, stop, restart, console.
#!/bin/sh
#
# <%=@service%> This shell script takes care of starting and stopping
# the <%=@service%> service.
#
# chkconfig: 2345 65 35
# description: <%=@description%>
#
SERVICE=<%=@service%>
@pdeschen
pdeschen / static-server.js
Created April 6, 2011 19:58
A node.js static file server using mime.
var libpath = require('path'),
http = require("http"),
fs = require('fs'),
url = require("url"),
mime = require('mime');
var path = ".";
var port = 8088;
http.createServer(function (request, response) {
@pdeschen
pdeschen / apex.sh
Created November 8, 2017 16:31
medium/serverless/apex
#!/bin/bash
apex deploy
apex invoke coa < test/coa-event.json
apex logs
@pdeschen
pdeschen / S3EventHandler.java
Created November 8, 2017 14:31
medium/serverless/S3EventHandler.java
@Override
public Void handleRequest(S3Event event, Context context) {
List<S3EventNotificationRecord> records = event.getRecords();
...
String bucket = record.getS3().getBucket().getName();
String key = decodeKey(record.getS3().getObject().getKey());
...
// fetch recording off S3 bucket
S3Object object = getS3Object(bucket, key);
@pdeschen
pdeschen / jetty.sh
Last active May 6, 2016 16:09
run-jetty-run!
#!/bin/bash
# usage: jetty -Dfoo=bar --path services --port 8080 path/to/war/file.war
# last 5 args are forwarded to jetty while remainder (if any) is forward to jvm
# such as system properties or remote debugging ala
# -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
length=$(($#-5))
jvm_args=${@:1:$length}
jetty_args=${@:$length+1:$(($#))}
@pdeschen
pdeschen / shelter
Last active January 1, 2016 22:49
shelter kick start
#!/bin/bash
VIRTUAL_BOX_VERSION=${1:-4.3}
VAGRANT_VERSION=${2:-1.4.2}
ARCH=`arch`
if [! -e /etc/redhat-release ] ; then
echo "Only RHEL flavour supported."
exit 1;
fi
@pdeschen
pdeschen / rivr-showcase.java
Last active December 18, 2015 14:59
Rivr showcase
if (login() == null) return STATUS_INVALID_USER;
Interactions mainMenu = newInteraction("main-menu")
.dtmfBargeIn(1)
.audio(audioPath("vm-youhave"))
.synthesis("1")
.audio(audioPath("vm-message"))
.noInputTimeout(DEFAULT_TIMEOUT)
.toInteractions();
@pdeschen
pdeschen / control.java
Last active December 18, 2015 14:59
Rivr Flow Control
String menu;
do {
menu = processDtmfTurn(mainMenu);
if ("0".equals(menu)) {
mailboxConfigure();
} else if ("1".equals(menu)) {
messageMenu();
@pdeschen
pdeschen / data.java
Last active December 18, 2015 14:59
Rivr data structure
String username;
String password;
int tries = 0;
do {
tries++;
username = processDtmfTurn(askLogin);
password = processDtmfTurn(askPassword);
askLogin = incorrect;
} while (!validate(username, password) && tries < 3);
if (tries == 3) {