Skip to content

Instantly share code, notes, and snippets.

Avatar

Evan Carroll EvanCarroll

View GitHub Profile
View recon.rs
let mut res = config
.connect(tokio_postgres::NoTls)
.await;
let (dbh, connection);
loop {
match res {
Err(_) => {
View gist:24dc1b7f058801543d18d890696d8996
// 1. Must only say "ClientError::*" ONCE.
// 2. Must return Result<Vec<String>, ClientError::*>
// 3. No nesting blocks or nested closures
// 4. Can be no unwrap, or try macro
//use std::ops::Deref;
let services = document
.select("ul.info")
.ok()
.and_then( |mut select| select.nth(1) )
.as_ref()
View gist:2d826bcbea7b39c1a65c638b82bc4f13
// 1. Must only say "ClientError::*" ONCE.
// 2. Must return Result<usize, ClientError::IndexParseError>
// 3. No nesting blocks, according to RustFMT
// 4. Can be no unwrap, or try macro
//use std::ops::Deref;
let services = document
.select("ul.info")
.ok()
.and_then( |mut select| select.nth(1) )
.as_ref()
View gist:aa239a6ee69c25b77755668919d9ff2f
// 1. Must only say "ClientError::IndexParseError" ONCE.
// 2. Must return Result<usize, ClientError::IndexParseError>
// 3. No nesting blocks
let last_id = document.select("div.cart:nth-child(1)")
.ok()
.and_then(|mut x| x.next() )
.and_then(|x| {
x.attributes
.borrow()
.get("id")
View steam system info
Computer Information:
Manufacturer: Unknown
Model: Unknown
Form Factor: Laptop
No Touch Input Detected
Processor Information:
CPU Vendor: GenuineIntel
CPU Brand: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
CPU Family: 0x6
View gist:44469d42a6e5b6e46207d1f0eada7e97
ecarroll=# explain SELECT j1.*, jsonb_typeof(j1.value) FROM jsonb_array_elements('[ 7,2, [6,7], 2,10 ]'::jsonb) AS j1 LEFT OUTER JOIN LATERAL jsonb_array_elements(j1."value") ON jsonb_typeof(j1.value) = 'array';
QUERY PLAN
-------------------------------------------------------------------------------------
Nested Loop Left Join (cost=0.01..251.25 rows=100 width=64)
Join Filter: (jsonb_typeof(j1.value) = 'array'::text)
-> Function Scan on jsonb_array_elements j1 (cost=0.00..1.00 rows=100 width=32)
-> Function Scan on jsonb_array_elements (cost=0.00..1.00 rows=100 width=0)
(4 rows)
@EvanCarroll
EvanCarroll / enjoy.c
Last active Aug 16, 2018
Why C is impossible to teach?
View enjoy.c
#include <stdio.h>
int a[2][2] = {{1,2},{3,4}};
int (*b)[2] = a;
int main () {
printf("%d\n", *b[1]);
printf("%d\n", (*b)[1]);
printf("%d\n", (*b+1)[1]);
printf("%d\n", (*(b+1))[1]);
View ch3.js
function f() {
let counter = 0;
return function () {
counter = counter + 1;
return function () { return counter }
}
}
Explain what the above code does and how we can use it.
View make.sh
#!/bin/sh
export PGROOT=/home/ecarroll/code/postgres/
gcc \
-I "$PGROOT/src/include/" \
-I "$PGROOT/src/interfaces/ecpg" \
-I "$PGROOT/src/interfaces/ecpg/include" \
./test.c \
-o a.out
View PG Serializability
Session 1
====
Will sleep for 5 seconds giving you time to launch TXN2.
DROP TABLE foo;
CREATE TABLE foo(x) AS
VALUES (1),(2),(3);