Skip to content

Instantly share code, notes, and snippets.

View ddrscott's full-sized avatar

Scott Pierce ddrscott

View GitHub Profile
@ddrscott
ddrscott / sidekiq_web
Created May 10, 2018 15:17
Standalone Sidekiq Web Server
#!/usr/bin/env ruby
# Run Sidekiq Web Standalone
require 'rack'
require 'sidekiq'
require 'sidekiq-ent'
require 'sidekiq-pro'
Sidekiq.configure_client do |config|
config.redis = { :size => 1 }
@ddrscott
ddrscott / README.md
Last active April 10, 2018 05:53
Mandelbrot Postgres SQL

Mandelbrot

Why were RECURSIVE queries implemented in Postgres? For the Mandelbrot set!

Results

                                         line
---------------------------------------------------------------------------------------
 @@@@@@@@@00000000%%%%%%%%%%%%%%%%%%%%%%%%%%%XXXXXXXXXXxxxxxxxx*xxx+xxXXXXXXX%%%%%%%%0
 @@@@@@@@000000%%%%%%%%%%%%%%%%%%%%%%%%%%%XXXXXXXXXXXxxxxxxxxxx=.=xxxxxxxXXXXXXX%%%%%%
@ddrscott
ddrscott / bowling.sql
Created March 23, 2018 14:22
Bowling score solver in SQL
WITH frames AS (
-- Empty row to set columns names and types
SELECT null::integer AS frame, ARRAY[0] AS rolls WHERE 1 = 0
UNION SELECT 1, ARRAY[ 9, 1 ]
UNION SELECT 2, ARRAY[ 10 ]
UNION SELECT 3, ARRAY[ 2, 4 ]
UNION SELECT 4, ARRAY[ 0, 10 ]
UNION SELECT 5, ARRAY[ 10 ]
UNION SELECT 6, ARRAY[ 10 ]
UNION SELECT 7, ARRAY[ 8, 2 ]
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