Skip to content

Instantly share code, notes, and snippets.


James R Qualls sourcec0de

View GitHub Profile
sourcec0de /
Created Apr 10, 2018 — forked from andrewn/
Testing SSL (LetsEncrypt certificate and loopback domain)

Testing SSL (LetsEncrypt certificate and loopback domain)

General approach

This sets up a publically-available domain that loops back to localhost IP address For example, this address could be if we controlled the domain. This relies on having a public domain name whose DNS records you can control. We can then generate LetsEncrypt certificates for this domain.

Our HTTP server runs on localhost:80 (default HTTP port). This lets us visit in a web browser and see the server running on localhost:80.

We then run an HTTPS proxy server on localhost:443 (default HTTPS port) that uses the LetsEncrypt certificates we generated for Visiting hits the proxy, which returns the correct certificates meaning the browser displays the "Secure" message. The proxy then passes the request through to the HTTP server.


What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would

sourcec0de / gist:ebe645f34c0a81eaa1408cf4db7f0336
Created Nov 6, 2017 — forked from chanks/gist:7585810
Turning PostgreSQL into a queue serving 10,000 jobs per second
View gist:ebe645f34c0a81eaa1408cf4db7f0336

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

View Intercom

Intercom user_hash

Remember that your secret key should never be exposed to the public

  • So Javascript code below should only be used for testing unless modified and used to run on a server
sourcec0de /
Created Mar 27, 2017 — forked from denji/
NGINX tuning for best performance

Moved to git repository:

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.



This PostgreSQL extension provides some functions for querying hstore arrays.


  • count_elements(elements hstore[], pattern text). returns the number of elements that match the given pattern.
  • multi_count_elements(elements hstore[], patterns text[]). returns an array
sourcec0de / haproxy.cfg
Created Oct 18, 2016
Here's a sample WORKING haproxy config for websockets / socketio. We were able to get socketio working on an Amazon ELB with just one node, but when we added multiple nodes, we saw weird client issues. So, we decided to use HAProxy on Ubuntu 12.04 and spent significant time trying to get just the right configuration (haproxy.cfg). Note though th…
View haproxy.cfg
log local0
log global
option httplog
frontend unsecured *:80
View gist:3524f4c4202e19569002031da6331ce7
package main
import (
const (
View spooler.go
// package spooler implements a disk-persistent queue.
// Spooler uses MDB (LMDB) to implement a queue of byteslices. Its intended usecase
// is to enqueue work items received by a service before later working them off.
// Note that Spooler only flushes to disk up to once every 25ms. As a result,
// if the process or machine crashes unexpectedly, the most recent 25ms of work
// can be lost. This decision effectively increases throughput by 10,000%,
// but makes spooler unsuitable for jobs that absolutely cannot be allowed to fail
// under any circumstances.
package spooler
sourcec0de / proxy.go
Created Aug 13, 2016 — forked from montanaflynn/proxy.go
Golang reverse proxy
View proxy.go
package main
import (
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {