Skip to content

Instantly share code, notes, and snippets.

View ddrscott's full-sized avatar

Scott Pierce ddrscott

View GitHub Profile
use std::io::{self, BufRead, BufReader, BufWriter, Write};
static READ_BUF_SIZE : usize = 1024 * 1024;
fn main() {
let mut reader = BufReader::with_capacity(READ_BUF_SIZE, io::stdin());
let mut writer = BufWriter::new(io::stdout());
let mut buffer = vec![];
while reader.read_until(b'\n', &mut buffer).unwrap() > 0 {
extern crate rand;
use std::io;
use rand::Rng;
use std::cmp::Ordering;
/// Thanks: https://doc.rust-lang.org/book/first-edition/guessing-game.html
fn main() {
println!("Guess the number!");

Cat

cat

time cat /tmp/lines_5m.csv > /dev/null
# => 0.01s user 0.26s system 99% cpu 0.277 total

./veedrac

@ddrscott
ddrscott / main.rs
Created March 5, 2018 04:24
Rust Guessing Game
extern crate rand;
use std::io;
use rand::Rng;
use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
FROM postgres:9.3-alpine
# Build scratch.sql by running:
# $ pg_dump --no-owner --no-acl scratch > scratch.sql.gz
COPY scratch.sql /docker-entrypoint-initdb.d/
@ddrscott
ddrscott / head.html
Last active February 22, 2018 20:42 — forked from magsout/head.html
Minimum Web App <head> configuration
<!DOCTYPE html>
<html lang="en" manifest="/manifest.appcache">
<head>
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
<meta charset="UTF-8">
<!-- Meta SEO -->
<title>Web App</title>
<meta name="author" content="author">
<meta name="description" content="Description">
<!-- RWD -->
@ddrscott
ddrscott / sqlpp.rb
Created February 13, 2018 22:24
Helper to beautify SQL statements. Works as file or pipe.
#!/usr/bin/env ruby
require 'open3'
# # Dependencies
# `sqlformat` and `pygmentize` are Python programs :/
# make sure it's installed and available in your path.
# ```
# $ pip install --upgrade sqlparse
# $ pip install --upgrade pygment
# $ export PATH=$PATH:~/Library/Python/3.5/bin
@ddrscott
ddrscott / gdax_ticker.rb
Created February 13, 2018 17:29
GDAX Websocket listener. Publishes to Redis queue
#!/usr/bin/env ruby
class GdaxTicker
attr_accessor :writer, :stats
attr_reader :socket, :feed_url
DEFAULT_WS_URL = 'wss://ws-feed.gdax.com'
PUBLISH_CHANNEL = 'altalarms:datum'
@ddrscott
ddrscott / overlaps.sql
Created January 12, 2018 16:25
Demonstration of OVERLAPS keyword vs checking date range with `>=` and `<=`
SELECT
t1.*,
(start_date, end_date) overlaps (range_start, range_end) as overlaps_func,
(start_date <= range_end) AND (end_date >= range_start) as overlap_bool
FROM generate_series('2016-12-01'::date, '2017-03-10'::date, '1 day'::interval) as gs(date)
JOIN LATERAL (
SELECT
'2017-01-01'::date start_date,
'2017-01-15'::date end_date,
(gs.date::date - '30 day'::interval)::date range_start,
@ddrscott
ddrscott / export_import.sh
Last active January 5, 2018 15:32
Export specific records from Postgres and import into another DB in a different docker host.
# export source data to file
psql anon -c "copy (SELECT * FROM assets WHERE color='red') to stdout csv header" > assets.csv
# create new database instance (without password)
docker run --name postgres-9.6 -e POSTGRES_PASSWORD='' -d -p 65436:5432 postgres:9.6
# copy table screma
pg_dump --schema-only --table=assets anon > schema.sql
# might need to remove foreign keys