Skip to content

Instantly share code, notes, and snippets.

View sj26's full-sized avatar
🤹‍♂️

Samuel Cochran sj26

🤹‍♂️
View GitHub Profile
@sj26
sj26 / phpserialize.py
Created February 2, 2010 09:53
Python port of PHP serialize() and unserialize()
#!/usr/bin/python -u
"""
Python port of PHP serialize() and unserialize()
by Samuel Cochran <sj26@sj26.com>
I couldn't find a nice, fairly efficient implementation of serialize/unserialize for Python... so I wrote one. I didn't use str().partition because I wanted Python <2.5 compatibility.
TODO: Performance review. There's an awful lot of string copying. >.>
@sj26
sj26 / assets.rake
Last active May 13, 2023 04:42
Don't discard cache during asset precompile. Full explanation and caveats: http://sj26.com/2013/02/09/the-asset-pipeline-isnt-actually-slow
# Stick this in lib/tasks/assets.rake or similar
#
# A bug was introduced in rails in 7f1a666d causing the whole application cache
# to be cleared everytime a precompile is run, but it is not neccesary and just
# slows down precompiling.
#
# Secondary consequences are the clearing of the whole cache, which if using
# the default file cache could cause an application level performance hit.
#
# This is already fixed in sprockets-rails for rails 4, but we patch here for
TIM:TIM:TIM:TIM:TIM:TIM
_^___
T __/ [] \
TIM===__ \
M \________]
I I
--------/
@sj26
sj26 / slack-archive-redirect.user.js
Created July 25, 2022 00:01
Open slack in the browser straight away — no more "open this link in your browser"
// ==UserScript==
// @name slack-archive-redirect
// @namespace https://sj26.com/slack-archive-redirect
// @version 1
// @description Open slack in the browser straight away
// @author sj26@sj26.com
// @match https://*.slack.com/archives/*
// @grant none
// ==/UserScript==
@sj26
sj26 / activerecord-lifetime.rb
Created March 3, 2022 01:38
ActiveRecord Connection Lifetime controls for using postgres with an autoscaling pgbouncer service safely
# frozen_string_literal: true
# Connection lifetime for ActiveRecord
#
# Make sure that connections to the database can only live for a certain number
# of seconds. Once lifetime is reached, the underlying connection will be
# reconnected. This is enforced when checking out a connection for use from the
# pool. Use in combination with idle_timeout to enforce connection lifetime on
# idle connections as well.
#
import random
__all__ = ('corpus', 'words', 'lorem')
'''
Simple Lorem Ipsum generator for python with some probabilistic punctuation smarts.
The corpus is the full text of De finibus bonorum et malorum/Liber Primus from wikisource:
http://la.wikisource.org/wiki/De_finibus_bonorum_et_malorum/Liber_Primus
@sj26
sj26 / fastmail-auto-dark.user.js
Created January 28, 2020 12:22
Fastmail Auto Dark Mode
// I don't know how to inject this on load yet, but pasting this in a console makes the Fastmail theme change between light and dark when macOS is toggled between light and dark.
window.matchMedia("(prefers-color-scheme: dark)").addListener(function(query) {
var theme = query.matches ? "dark" : "minimal";
FastMail.theme.set("theme", theme);
FastMail.userPrefs.set("theme", theme);
});
@sj26
sj26 / gist:650811
Created October 28, 2010 07:05
MRO
class A
def initialize
puts "A initialized"
end
end
module B
def initialize_with_b
puts "B initialized"
end
@sj26
sj26 / apple_record.rb
Created June 23, 2013 04:58
How I do STI: Utilize descendent tracking and override model_name so they use the same URL helpers and parameters as their base class. Makes things like responders and form_for work as expected, while preserving things like to_partial_path.
class AppleRecord < Record
end
/* ==UserStyle==
@name trello-hide-workspace-nav
@description Hide new trello workspace nav when it is collapsed (press "[")
@match https://trello.com/*
==/UserStyle== */
[data-test-id="workspace-navigation-collapsed-container"] {
display: none !important;
}