Skip to content

Instantly share code, notes, and snippets.

@bobbytables
bobbytables / build.sh
Created February 18, 2017 15:49
Protocol Buffer build script for multiple folders
#!/usr/bin/env bash
# This script is meant to build and compile every protocolbuffer for each
# service declared in this repository (as defined by sub-directories).
# It compiles using docker containers based on Namely's protoc image
# seen here: https://github.com/namely/docker-protoc
set -e
REPOPATH=${REPOPATH-/opt/protolangs}
CURRENT_BRANCH=${CIRCLE_BRANCH-"branch-not-available"}

Redux WebSocket Middleware: Example

This Gist provides some code examples of how to implement WebSocket stream handling using a Redux middleware. Please be aware that this is only provided as an example and that critical things like exception handling have not been implemented.

A more complete version has been packaged, tested, and is available on GitHub as redux-websocket. This library has also been published to npm at @giantmachines/redux-websocket.

Middleware

This module represents the foundation of the middleware and implements the ideas presented above. The exported function is used during the creation of the Redux store (see the following snippet).

@rrafal
rrafal / sqlx_json.go
Created March 31, 2016 00:02
Use JSON field with golang sqlx driver
package main
import (
"encoding/json"
"errors"
"database/sql/driver"
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"log"
@prologic
prologic / swarm-create
Created December 23, 2015 06:16 — forked from jorelcb/swarm-create
bash script to create docker swarm cluster with docker machine and virtualbox
#!/bin/bash
# Script para generar entorno simulado de cluster Swarm con 3 nodos
# Creación de maquina default (se utilizara como cliente )
# docker-machine create -d virtualbox default
# eval $(docker-machine env default)
# Lanzamos swarm desde maquina default
SWARM_TOKEN=$(docker run swarm create)
@jeffturcotte
jeffturcotte / Template.html
Last active December 27, 2016 12:03
RequireJS per page module
<!doctype html>
<html>
<head>
<title>{{ title|title }}</title>
<link rel="stylesheet" href="/styles/common.css" />
<link rel="stylesheet" href="/styles/layout.css" />
</head>
<body>
{{ include('header.html') }}
@colaru
colaru / ModuleIntegrationTest.java
Created July 2, 2013 14:14
Integration test for Vert.x WebSocket server that insteed of responding to a request, register a Event Bus handler that send back to client all events on Event Bus for a given topic.
@Test
public void testWebSocketServer() {
long startTime;
long endTime;
startTime = System.currentTimeMillis();
container.logger().info("Starting web socket test");
HttpClient client = vertx.createHttpClient().setPort(8081).setHost("localhost").setMaxPoolSize(CONNS);
for (int i = 0; i < CONNS; i++) {
@HoundstoothSTL
HoundstoothSTL / anchor-scroll-with-offset.js
Created May 3, 2013 15:43
Anchor scroll with fixed header offset
(function($) {
$('a[href*=#]:not([href=#])').click(function()
{
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
|| location.hostname == this.hostname)
{
var target = $(this.hash),
headerHeight = $(".primary-header").height() + 5; // Get fixed header height
@77web
77web / 1_security.yml
Created February 25, 2013 07:23
How to switch user accounts between two(or more) different firewalls when using Symfony\Bundle\SecurityBundle
//you may have some more configs here...
providers:
user:
entity: { class: MyAppBundle:User, property: loginEmail }
admin:
entity: { class: MyAppBundle:Admin, property: username }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
@cecilemuller
cecilemuller / get_combinations.php
Created February 1, 2013 03:13
PHP: Get all combinations of multiple arrays (preserves keys)
<?php
function get_combinations($arrays) {
$result = array(array());
foreach ($arrays as $property => $property_values) {
$tmp = array();
foreach ($result as $result_item) {
foreach ($property_values as $property_value) {
$tmp[] = array_merge($result_item, array($property => $property_value));
}
@jmather
jmather / AcceptHeaderKernelListener.php
Created September 29, 2012 22:48
RESTful Versioned API with Silex using Accept header
<?php
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AcceptHeaderKernelListener implements EventSubscriberInterface
{