Skip to content

Instantly share code, notes, and snippets.

require 'spec_helper'
describe Book do
it "has same join behavior for logically equivalent subqueries" do
author = Author.create
book = Book.create!(cost: 100, author: author)
2.times { Chapter.create!(book: book) }
sub_query1 = Book.arel_table[:author_id].in([author.id])
sub_query2 = Book.arel_table[:author_id].in(
set nocompatible
set viminfo='20,\"500 " Keep a .viminfo file.
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if ! exists("g:leave_my_cursor_position_alone") |
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif |
# search markdown links and convert
# [do some cool thing](#fn-infer) => <a name="do-some-cool-thing"></a>[do some cool thing](#do-some-cool-thing)
def transform(line)
fn_name = 'fn-infer'
md_regex = %r{[^`]?\[(.*)\]\(##{fn_name}\)}
name_regex = %r{##{fn_name}}
a_regex = %r{\[}
p line
if (line =~ md_regex)
@eeeschwartz
eeeschwartz / export_spreadsheet_to_calendar.js
Last active May 13, 2023 00:54
Google Apps Script to publish spreadsheet to calendar
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Export Events",
functionName : "exportEvents"
}];
sheet.addMenu("Calendar Actions", entries);
};
function return1() {
class AnyOldClass
attr_accessor :array_attr
def initialize
self.array_attr = []
this_is_fine
self.array_attr = []
this_also_fine
@eeeschwartz
eeeschwartz / gist:dd18e550ea8da5850c6f
Last active August 29, 2015 14:03
Batch geocode with throttling
// based on https://github.com/mapbox/geo-googledocs
// install the script and run the geocode once to set the api and key
// in the script window, set up a trigger in `Resources > Current Project triggers`
// run geocodeFromCache once a minute
//
// Global variables
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sheet = ss.getActiveSheet(),
activeRange = ss.getActiveRange(),
settings = {};
@eeeschwartz
eeeschwartz / gist:353eacdf6cb3199c14ad
Last active August 29, 2015 14:05
Create a CKAN resource and continually update it by upserting
curl -v $CKAN_BASE_URL/api/action/resource_create \
--form name="Complaints" \
--form id="$resource_id" \
--form package_id="$package_id" \
--form format="csv" \
--form url="http://104.131.23.252/datastore/dump/$resource_id" \
-H "Authorization: $CKAN_API_KEY"
sleep 5
@eeeschwartz
eeeschwartz / createBuildingPermits.sh
Last active August 29, 2015 14:07
Configure datastore entry for code-enforcement CKAN resource
CKAN_BASE_URL=http://www.civicdata.com
CKAN_API_KEY=from-ckan-users-profile-page
resource_id='2691aff1-e555-48d3-9188-aebf1fa8323e'
fields='[{"id":"ID","type":"integer"},{"id":"Date","type":"date"},{"id":"Address","type":"text"},{"id":"Suite","type":"text"},{"id":"PermitType","type":"text"},{"id":"ConstructionCost","type":"integer"},{"id":"OwnerName","type":"text"},{"id":"Contractor","type":"text"},{"id":"parcelId","type":"text"},{"id":"lat","type":"float"},{"id":"lng","type":"float"}]'
curl -v $CKAN_BASE_URL/api/3/action/datastore_create \
-d '{"resource_id": "'$resource_id'", "fields": '$fields', "primary_key":"ID", "force":"true"}' \
-H "Authorization: $CKAN_API_KEY"
@eeeschwartz
eeeschwartz / gist:909a4cfab8e5b81fbb49
Created November 5, 2014 17:51
Quick and dirty esri REST to GeoJSON adapter
def format_leaf_collection(geo_json)
esri_formatted = JSON.parse(geo_json)
features = esri_formatted['features'].map do |feature|
properties = feature['attributes']
title = "Hello! Leaf collection status in your area is now '#{properties['Status']}'."
title += " Collection dates are #{properties['Dates']}" if properties['Dates']
{
type: "Feature",
id: properties['OBJECTID'],
@eeeschwartz
eeeschwartz / close_other_subaccount.sh
Last active August 29, 2015 14:08
Migrate number to citygram subaccount from another subaccount
other_subaccount_sid=
other_phone_sid=
citygram_subaccount_sid=
master_account_sid=
master_account_auth_token=
curl -XPOST "https://api.twilio.com/2010-04-01/Accounts/$other_subaccount_sid.json" \
-d "Status=closed" \
-u "$master_account_sid:$master_account_auth_token"