Skip to content

Instantly share code, notes, and snippets.

View Philmod's full-sized avatar

Philippe Modard Philmod

View GitHub Profile
@Philmod
Philmod / socketHangUp.js
Created March 21, 2013 18:23
This is simple way to reproduce the socket hang up. Hope it can help.
// npm install express supertest
// node socketHangUp.js
/**
* Express server.
*/
var express = require('express')
, request = require('supertest')
;
for (var i=0; i<10; i++) {
setTimeout(function() { // to simulate a random I/O call
console.log('i = ', i);
}, 100);
}
/*
i = 10
i = 10
i = 10
@Philmod
Philmod / fb_page
Created August 12, 2013 22:38
Post on a facebook page.
var request = require('request');
function postMessage(access_token, page_id, message, response) {
// Specify the URL and query string parameters needed for the request
var url = 'https://graph.facebook.com/' + page_id + '/feed';
var params = {
access_token: access_token,
message: message
};
global
log 127.0.0.1:514 local0
defaults
mode http
log global
option httplog
option http-server-close
option dontlognull
option redispatch
@Philmod
Philmod / async_test.js
Created January 21, 2015 19:38
Async with a null value returned
var async = require('async')
, _ = require('underscore');
var array = [1,2,3,4,5];
async.map(array, function(item, cb) {
if (item === 3)
return cb();
else
return cb(null, item*2);
@Philmod
Philmod / haproxy.cfg
Created August 14, 2016 22:29
HAProxy configuration for the socket.io chat example, splitted into frontend and websocket servers.
global
log 127.0.0.1 local0
maxconn 8192
user haproxy
group haproxy
defaults
log global
mode http
option httplog
@Philmod
Philmod / google-container-kubernetes.js
Last active November 26, 2018 18:10
Deploy a new image from Google Cloud Container Builder to Kubernetes, using Google Cloud Functions.
const async = require('async');
const google = require('googleapis');
const k8s = require('kubernetes-client');
const container = google.container('v1');
const PROJECT_ID = 'node-example-gke';
const ZONE = 'us-east1-b';
const CLUSTER_ID = 'node-example-cluster';
const NAMESPACE = 'default';
@Philmod
Philmod / gcb-kubernetes.yaml
Last active July 25, 2021 05:34
Deploy a new image from Google Cloud Container Builder to Kubernetes, by storing GKE credentials in GCS.
steps:
- name: 'gcr.io/cloud-builders/npm'
args: ['install']
- name: 'gcr.io/cloud-builders/npm'
args: ['test']
- name: 'gcr.io/cloud-builders/docker'
args: ["build", "-t", "gcr.io/$PROJECT_ID/frontend:$REVISION_ID", "."]
- name: 'gcr.io/cloud-builders/docker'
args: ["push", "gcr.io/$PROJECT_ID/frontend:$REVISION_ID"]
- name: 'gcr.io/cloud-builders/gcloud'
@Philmod
Philmod / gcf_datastore.js
Created March 31, 2017 17:24
A GCFunction to write data from PubSub to Datastore.
const datastore = require('google-cloud').datastore;
const _PROJECT_ID = 'my-project';
var datastoreClient = datastore({
projectId: _PROJECT_ID
});
exports.subscribe = function subscribe(event, callback) {
const pubsubMessage = event.data;
@Philmod
Philmod / Dockerfile.multistage
Last active October 10, 2017 21:13
Builder pattern: one image to perform a build and another to have a lean runtime image, in a same Dockerfile.
# First Stage
FROM golang:1.6-alpine
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
# Second Stage
FROM alpine
EXPOSE 8000