Skip to content

Instantly share code, notes, and snippets.

View maccman's full-sized avatar
🦜
gpu poor

Alex MacCaw maccman

🦜
gpu poor
View GitHub Profile
@maccman
maccman / counter.sql
Created July 7, 2013 03:11
Postgres counter cache using triggers.
--
-- Name: c_posts_voted(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION c_posts_voted() RETURNS trigger
LANGUAGE plpgsql
AS $$ BEGIN
UPDATE "posts" SET voted_user_ids = array_append(voted_user_ids, NEW.user_id) WHERE "id" = NEW.post_id;
RETURN NEW;
END;
@maccman
maccman / app.py
Created August 8, 2012 23:30
Stripe Flask Example
import os
from flask import Flask, render_template, request
import stripe
stripe_keys = {
'secret_key': os.environ['SECRET_KEY'],
'publishable_key': os.environ['PUBLISHABLE_KEY']
}
stripe.api_key = stripe_keys['secret_key']
import {assertString} from 'plugins/assert'
type TemplateContext = {
input: string
customPrompt?: string
}
type Template = (context: TemplateContext) => string
type ServerPredictionPrompt = {
.marquee {
@apply flex-1 flex overflow-hidden;
}
.marquee .marquee-inner {
@apply truncate flex-1;
}
.marquee.marquee-active .marquee-inner {
@apply flex-none;
@maccman
maccman / jquery.onclose.coffee
Last active July 3, 2022 08:17
jQuery plugin to notify users if they close the page, and there are still some Ajax requests pending.
$ = jQuery
TRANSFORM_TYPES = ['PUT', 'POST', 'DELETE']
$.activeTransforms = 0
$(document).ajaxSend (e, xhr, settings) ->
return unless settings.type in TRANSFORM_TYPES
$.activeTransforms += 1
function whichTransitionEvent(){
var t;
var el = document.createElement('fakeelement');
var transitions = {
'transition':'transitionend',
'MSTransition':'msTransitionEnd',
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
}
$ = jQuery
TIMEOUT = 20000
lastTime = (new Date()).getTime()
setInterval ->
currentTime = (new Date()).getTime()
# If timeout was paused (ignoring small
# variations) then trigger the 'wake' event
if currentTime > (lastTime + TIMEOUT + 2000)
@maccman
maccman / juggernaut_heroku.md
Created June 2, 2011 01:26
Juggernaut on Heroku

Clone repo:

git clone git://github.com/maccman/juggernaut.git
cd juggernaut

Create Heroku app:

heroku create myapp --stack cedar
heroku addons:add redistogo:nano

git push heroku master

@maccman
maccman / batch_request.csv
Last active August 4, 2021 22:20
Clearbit Batch Example
email
alex@clearbit.com
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __FILE__)
require 'cramp'
require 'cramp/controller'
Cramp::Controller::Websocket.backend = :thin
class SyncroLongPollSubscribe < Cramp::Controller::Action
on_start :post_init
on_finish :unbind