Skip to content

Instantly share code, notes, and snippets.

View jaylevitt's full-sized avatar

Jay Levitt jaylevitt

View GitHub Profile
@jaylevitt
jaylevitt / demo.sql
Created September 20, 2012 00:14
Subquery in a JOIN not getting restricted
drop schema if exists jaytest cascade;
create schema jaytest;
set search_path to jaytest;
create table questions (
id int not null primary key,
user_id int not null
);
insert into questions
@jaylevitt
jaylevitt / 1. NewEgg reply
Created June 14, 2012 03:51
Yes, some people have bad experiences with NewEgg
Reference number: LTK41902794173X Please use this ticket number in any correspondence with Newegg.com.
Subject: RMA #20851593 shipping
Dear Customer,
Thank you for contacting Newegg.
I am sorry for this inconvenience. I have waived the restocking fee on the RMA # 20851593. However, we do not return the original shipping cost for customers. However, I have sent $52.41 credit back to your source of payment as a one time exception to cover the original shipping cost.
@jaylevitt
jaylevitt / 1-failcase.rb
Created May 23, 2012 14:43
using Perl-style "and"?
#!/usr/bin/env ruby
puts "true" and return if true
puts "fell through"
abort
class Pet < ActiveRecord::Base
has_many :user_pets
belongs_to :user, :through => :user_pets
validates :name, :allow_nil => true, :inclusion => { :in => Pet.valid_pets }
def self.valid_pets
['fish',
'bird',
'tree',
@jaylevitt
jaylevitt / gist:2279270
Created April 1, 2012 22:52
Posts with position > position of last known ID
CREATE TABLE posts
(
id int primary key,
position int,
animal text
);
INSERT INTO posts
(id, position, animal)
VALUES
mc$prepare_cache_copy: procedure (compname, slot, code);
declare compname char(32)var;
declare slot bin(15);
declare code bin(15);
if (^ mc$manager_lock_slot (compname, LOCK$EXCLUSIVE)) then
return;
mc$current_slot.flags.requested = TRUE;
slot = mc$current_slot_n;
@jaylevitt
jaylevitt / query.sql
Created March 23, 2012 01:25
tappables sort by time query
SELECT tappables.id, max(
case
when tappables.type = 'SurveyReceipt'
then tappables.created_at
when taps.user_id = 2816
then taps.created_at
else
taps.skewed_created_at
end) as last_tap
FROM tappables
UPDATE tappables SET taps_count = count(taps.id)
FROM taps
WHERE taps.tappable_id = tappables.id
# This file is used by Rack-based servers to start the application.
# Manually include newrelic first so it gets its route
require 'newrelic_rpm'
require 'new_relic/rack/developer_mode'
use NewRelic::Rack::DeveloperMode
require ::File.expand_path('../config/environment', __FILE__)
run Mindset::Application
SELECT tappables.id,
max(case
when tappables.type = 'Survey'
then case
when (not exists survey_responses) -- pseudo-code
then now() - random() * interval '1 day'
else
max(survey_responses.created_at)
end
when taps.user_id = :user_id