Skip to content

Instantly share code, notes, and snippets.

View simonmorley's full-sized avatar

Simon Morley simonmorley

  • London
View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#define BUF_SIZE 1024
int main(int argc, char **argv)
{
int ret = Z_OK;
z_stream strm;
@nagachika
nagachika / Gemfile
Created March 24, 2015 09:49
workaround for Google Cloud Pub/Sub via google-api-client.gem
source "https://rubygems.org"
gem "google-api-client", "0.8.3"
@nackjicholson
nackjicholson / unit-test-angularjs-grunt-karma-travis.md
Created December 22, 2014 05:37
Unit Testing with AngularJs, Grunt, Karma, and TravisCI

If you've done much reading about angularjs you've no doubt come across mention of karma, a test runner recommended especially for use with angularjs applications. The [angular-seed][1] project is a great way to get started with the basics of angular testing using karma, but for projects of any significant size you will soon hit the cieling in terms of organizational complexity. What I want to share in this article is the approach I have taken using [Grunt][2] and the [grunt-karma][3] plugin to sustainably manage my projects' client side unit tests and run them via [TravisCI][4]. I plan to write another entry about how to approach the actual minutia of unit testing angular code in the near future.

Karma, configuration for tests

Karma is really nothing more than a set of centralized configuration that builds a test runner for you. The advantage being that it allows you to easily execute tests in a headless browser, and output to the command line. As someone who has actually set all of that up from scratc

@alan-mushi
alan-mushi / json_parser.c
Last active March 25, 2024 19:23
Examples for the json-c tutorial.
/*
* A simple example of json string parsing with json-c.
*
* clang -Wall -g -I/usr/include/json-c/ -o json_parser json_parser.c -ljson-c
*/
#include <json.h>
#include <stdio.h>
int main() {
struct json_object *jobj;
@brianc
brianc / gist:f906bacc17409203aee0
Last active December 22, 2023 00:47
Some thoughts on node-postgres in web applications

Some thoughts on using node-postgres in a web application

This is the approach I've been using for the past year or so. I'm sure I'll change and it will change as I grow & am exposed to more ideas, but it's worked alright for me so far.

Pooling:

I would definitely use a single pool of clients throughout the application. node-postgres ships with a pool implementation that has always met my needs, but it's also fine to just use the require('pg').Client prototype and implement your own pool if you know what you're doing & have some custom requirements on the pool.

@wolfeidau
wolfeidau / events.go
Created August 31, 2014 03:57
kako types
type Event struct {
UserID string // GUID of the user who owns this series
Key string // name of the series, otherwise known as key
Measurement *Measurement // measurement
LogEntry *LogEntry // log event
Timestamp time.Time // when measurement was taken
}
func (e *Event) ToRowMap() map[string]bigquery.JsonValue {
@simonmorley
simonmorley / gist:d16261a1b45e28af6455
Last active January 4, 2016 10:44
Google Cloud Compute Create Snapshot with Rotate
#!/bin/ruby
require 'json'
require 'time'
require 'syslog'
class Snapshot
def initialize()
@format = 'json'
@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@simonmorley
simonmorley / gist:5901be947407ea427f0a
Last active January 19, 2017 21:36
Import and Alias Mulitple Indexes To Elasticsearch Rails
# A collection of Rake tasks to facilitate importing data from yout models into Elasticsearch.
# This will import the index as an alias, update the alias and delete the old ones
# It will also allow the importation of indexes via arguments
# Add this e.g. into the `lib/tasks/elasticsearch.rake` file in your Rails application:
#
# require 'elasticsearch/rails/tasks/import'
#
# To import the records from your `Article` model, run:
@niksumeiko
niksumeiko / git.migrate
Last active May 13, 2024 15:34
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.