Skip to content

Instantly share code, notes, and snippets.

View toadkicker's full-sized avatar
🏠
Let's fix some stuff

Todd Baur toadkicker

🏠
Let's fix some stuff
View GitHub Profile
daemon off;
error_log /dev/stdout error;
worker_processes 4;
events {
worker_connections 1024;
}
@chanks
chanks / gist:7585810
Last active January 10, 2025 03:03
Turning PostgreSQL into a queue serving 10,000 jobs per second

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

@toadkicker
toadkicker / gist:7609641
Last active June 18, 2023 19:44
This is the intro in Lion King. 'Pride Rock'. I use it instead of lorem ipsum sometimes.
Ndabe zitha nkosi yethu mholi wezwe lethu lefatshe la bonata rona lea halalela busa le lizwe bo busa le lizwe bo busa le lizwe bo Lethu busa. Ngoxolo is'khathi sifikile is'khathi busa iyo is'khathi sifikile busa lomhlaba is'khathi sifikile is'khathi sifikile. Busa simba busa bimba. Hem na iyo hem na iyo mem na nkosi bo. Busa simba iyo hem na iyo. Oh busa simba iyo Hem na iyo. Oh busa nkosi bo Hem na nkosi bo. Oh busa simba iyo busa simba iyo. Busa simba iyo ubuse ngo thando. Ubuse ngo thando ubuse. Ngo xolo busa simba, busa simba ubuse ngo xolo. Ubuse ngo thando ubuse ngo xolo. Ubuse ngo thando ubuse ngo xolo.
@gonzalo-bulnes
gonzalo-bulnes / XXXXXXXXXXXXX_add_authentication_token_to_users.rb
Last active March 6, 2019 15:15
(Update: I've packaged this gist into a gem to make its use easier, see: https://github.com/gonzalo-bulnes/simple_token_authentication.) Add token authentication to your Rails API. Follows the José Valim recomendations and is fully compatible with Devise (tokens are created the first time users sign in). See https://gist.github.com/josevalim/fb7…
# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end
@erichurst
erichurst / US Zip Codes from 2013 Government Data
Created December 9, 2013 23:00
All US zip codes with their corresponding latitude and longitude coordinates. Comma delimited for your database goodness. Source: http://www.census.gov/geo/maps-data/data/gazetteer.html
This file has been truncated, but you can view the full file.
ZIP,LAT,LNG
00601,18.180555, -66.749961
00602,18.361945, -67.175597
00603,18.455183, -67.119887
00606,18.158345, -66.932911
00610,18.295366, -67.125135
00612,18.402253, -66.711397
00616,18.420412, -66.671979
00617,18.445147, -66.559696
00622,17.991245, -67.153993
@bigfive
bigfive / example_mailer_spec.rb
Created January 7, 2014 08:14
ActionMailer RSpec helpers. Makes mailer test more similar to controller tests in that you can test that instance variables are assigned for rendering
require "spec_helper"
describe ExampleMailer do
describe :new_user do
let(:user) { FactoryGirl.create :user }
it "sends to the correct addresses" do
# :mail is similar to the controller specs 'get', 'post' etc methods
mail :new_user, user
// http://davidwalsh.name/javascript-debounce-function
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
"UserData": {
"Fn::Base64": { "Fn::Join":["", [
"#!/bin/bash -ex\n",
"apt-get update\n",
"apt-get -y install python-setuptools\n",
"mkdir aws-cfn-bootstrap-latest\n",
"curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1\n",
"easy_install aws-cfn-bootstrap-latest\n",
"/usr/local/bin/cfn-init --stack ", { "Ref":"AWS::StackName" }, " --resource WebServer", " --region ", { "Ref": "AWS::Region" }, "\n",
"\n",
@brock
brock / webinar.md
Last active August 29, 2015 14:00
a crazy good webinar on using webstorm. these are notes to accompany the recorded session that will be published the week of Mon, April 28th

WebStorm AngularJS Webinar

AngularJS

  1. Install angular with: terminal: bower install angular
  2. Ctrl-space twice
  3. ng stuff works now
  4. Preferences: Editor: angularjs add whitespace
  5. Debug (there is a shortcut so you can do live edit and it updates in chrome)
  6. You can change your code style for html. Preferences: Code Style: HTML (worth a look through these settings)
  7. Cmd+Alt+L to reformat your code
@prograhammer
prograhammer / git-cheat-sheet.md
Last active November 4, 2024 02:58
Git cheat sheet for some useful Git commands and command scenarios.