Skip to content

Instantly share code, notes, and snippets.

View chochkov's full-sized avatar
💭
BOOM

Nikola Chochkov chochkov

💭
BOOM
View GitHub Profile
.:' .:' .:'
__ :'__ __ :'__ __ :'__
.'`__`-'__``. .'`__`-'__``. .'`__`-'__``.
:__________.-' :__________.-' :__________.-'
:_________: :_________: :_________:
:_________`-; :_________`-; :_________`-;
`.__.-.__.' `.__.-.__.' `.__.-.__.'
-- -h localhost -d test
DROP TABLE IF EXISTS customers;
DROP TABLE IF EXISTS products;
DROP TABLE IF EXISTS orders;
CREATE TABLE customers (
id integer,
name text,
city text,
-- I. Make sure the table is cleaned up before execution using the SQL verb `DROP`
DROP TABLE IF EXISTS users;
-- II. Create the table definition using the SQL verb `CREATE`
CREATE TABLE users (
id integer,
name text,
email text,
signup_date date
);
INSERT INTO users (id, full_name, email, created_at) (
VALUES
(1,'Mechelle','Cras@AliquamnislNulla.ca','2016-08-14'),
(2,'Reese','ultrices@Quisquepurussapien.com','2017-09-12'),
(3,'Anne','Phasellus@dolorsitamet.edu','2017-01-17'),
(4,'Whitney','Nunc.mauris@Aliquamrutrumlorem.net','2017-04-30'),
(5,'Kimberly','Donec.felis.orci@morbitristiquesenectus.org','2017-07-21'),
(6,'Eugenia','semper.rutrum@et.com','2017-10-23'),
(7,'Wing','vitae.velit.egestas@vehicula.org','2017-08-27'),
(8,'Brett','mauris@a.com','2016-06-17'),
@chochkov
chochkov / Users
Last active November 1, 2016 18:43
ReDI Sample Data
id,first_name,email,created_at
1,Mechelle,Cras@AliquamnislNulla.ca,2016-08-14
2,Reese,ultrices@Quisquepurussapien.com,2017-09-12
3,Anne,Phasellus@dolorsitamet.edu,2017-01-17
4,Whitney,Nunc.mauris@Aliquamrutrumlorem.net,2017-04-30
5,Kimberly,Donec.felis.orci@morbitristiquesenectus.org,2017-07-21
6,Eugenia,semper.rutrum@et.com,2017-10-23
7,Wing,vitae.velit.egestas@vehicula.org,2017-08-27
8,Brett,mauris@a.com,2016-06-17
9,Harrison,in.felis.Nulla@liberoettristique.ca,2016-08-20
DB_NAME='hstore_jsonb_test'
MAX_RECORDS=1e7
DICTIONARY="'ivan', 'dobri', 'pesho', 'genadi', 'smotlyo', 'metodi', 'dimitar', 'stamen', 'petyo', 'gosho'"
psql -U postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$DB_NAME'"
psql -U postgres -c "DROP DATABASE IF EXISTS $DB_NAME"
psql -U postgres -c "CREATE DATABASE $DB_NAME"
psql $DB_NAME -U postgres -c "
CREATE EXTENSION hstore;
@chochkov
chochkov / gist:7284325
Last active December 27, 2015 06:49
Compare PL/R implementation of an average to PostgreSQL `avg()`
CREATE OR REPLACE FUNCTION r_mean(float8) RETURNS FLOAT AS $$
return(mean(arg1))
$$ language 'plr';
CREATE AGGREGATE mean (
sfunc = plr_array_accum,
basetype = float8,
stype = _float8,
finalfunc = r_mean
);
@chochkov
chochkov / gist:5355936
Last active December 16, 2015 01:30
illustrate 2 features of PostgreSQL's common table expressions
-- this illustrates certain behaviour of CTE in Postgres.
-- define a new table and fill in some entries
-- ! make sure you dont mess up some existing prices table !
--
create table if not exists prices( id int, created_at int, price int);
insert into prices values (1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5);
--
-- we now have 5 records in `prices` at the start, then:
@chochkov
chochkov / exec.r
Created October 30, 2012 18:23
Rscript
#!/usr/bin/Rscript
library(RPostgreSQL)
library(data.table)
library(optparse)
opts.list <- list(
make_option(c('-d', '--day'), help='Global Rank for day')
# ... further options
)
Completed 500 Internal Server Error in 1746ms
ActionView::Template::Error (incompatible character encodings: UTF-8 and US-ASCII):
26: })();
27: %script
28: != google_ad_renderer.render
29:
30:
31: = csrf_meta_tag
32: = yield :header_script