Skip to content

Instantly share code, notes, and snippets.

@peterkeen
peterkeen / export_tiller.rb
Created Mar 4, 2018
Export a Tiller transaction spreadsheet as a ledger file while checking for duplicates in ledger-web database.
View export_tiller.rb
require 'rubygems'
require 'bundler/setup'
require 'pg'
require 'sequel'
require 'ledger_gen'
require 'google_drive'
SPREADSHEET_ID = 'your-google-sheet-id'
DATABASE_URL = 'postgres://username:password@host/database'
View ztdns.rb
require 'rubydns'
require 'httparty'
require 'lru_redux'
class ZeroTierAPI
include HTTParty
base_uri "https://my.zerotier.com/api"
headers 'Authorization' => "Bearer #{ENV['ZT_API_TOKEN']}"
View serve.rb
require 'rubydns'
INTERFACES = [
[:udp, "0.0.0.0", 5300],
[:tcp, "0.0.0.0", 5300]
]
IN = Resolv::DNS::Resource::IN
UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
View gist.rake
task :run_gist => :environment do
url = ENV['url']
raise "usage: rake run_gist url=https://gist.github.com/asdfasdfasdfasdf" unless url.present?
dir = Dir.mktmpdir
system("git clone #{url} #{dir}")
Dir.chdir(dir) do
raise "Gist does not have a script.rb file to execute" unless File.exists?('script.rb')
View payola_cla.md

Cora Street Press Individual Contributor License Agreement

Thank you for your interest in contributing to open source software projects (“Projects”) made available by Cora Street Press or its affiliates (“Cora Street Press”). This Individual Contributor License Agreement (“Agreement”) sets out the terms governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any manner, to Cora Street Press in respect of any of the Projects (collectively “Contributions”). If you have any questions respecting this Agreement, please contact pete@corastreetpress.com.

You agree that the following terms apply to all of your past, present and future Contributions. Except for the licenses granted in this Agreement, you retain all of your right, title and interest in and to your Contributions.

Copyright License. You hereby grant, and agree to grant

View do_backup.sh
#!/bin/bash
# This depends on a file named `/root/backup_dirs` containing a list of directories to backup
# one per line. All directories in that file, plus a database dump, will be archived together.
#
# Further, if you have a gitolite installationn, this will backup every repo in an individual archive.
set -e
set -x
set -o pipefail
@peterkeen
peterkeen / automatic.txt
Created Apr 8, 2015
Examples from Program Your Finances: Envelope Budgeting
View automatic.txt
= /Income:Salary/ and expr date >= [2015/04/01] && date < [2015/06/01]
* Assets:Funds:Water $50.00
* Liabilities:Funds:Water $-50.00
= /Income:Salary/ and expr date >= [2015/06/01]
* Assets:Funds:Water $55.00
* Liabilities:Funds:Water $-55.00
= /Expenses:Water/
* Liabilities:Funds:Water 1.0
@peterkeen
peterkeen / gist:79a9d7b9f068f8a199de
Created Jan 30, 2015
A silly torturous PG plan
View gist:79a9d7b9f068f8a199de
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------
Append (cost=1124.07..1134.09 rows=201 width=136) (actual time=13.030..13.052 rows=13 loops=1)
CTE months
-> Function Scan on generate_series x (cost=0.00..25.00 rows=1000 width=4) (actual time=0.042..0.064 rows=12 loops=1)
CTE monthly_income
-> HashAggregate (cost=293.73..293.74 rows=1 width=42) (actual time=12.623..12.625 rows=10 loops=1)
-> Seq Scan on ledger (cost=0.00..293.52 rows=12 width=42) (actual time=10.223..12.497 rows=27 loops=1)
Filter: ((account ~ 'Income:Consulting'::text) AND ((jtags ->> 'Client'::text) IS NOT NULL))
Rows Removed by Filter: 2741
View gist.rb
if Rails.env.production?
resp = HTTParty.get(@sale.product.file.url)
filename = @sale.product.file.url
send_data resp.body,
:filename => File.basename(filename),
:content_type => resp.headers['Content-Type']
else
filename = File.expand_path(Sale.last.product.file_file_name, Rails.root)
send_data File.open(@sale.product.file_file_name),