This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fizz Buzz in Tensorflow! | |
# see http://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/ | |
import time | |
import sys | |
import numpy as np | |
import tensorflow as tf | |
from utils import binary_encode, fizz_buzz_encode, fizz_buzz | |
#from models import gen, gen_all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open("/tmp/empty.json", O_RDONLY|O_CLOEXEC) = 12 | |
fstat(12, {st_mode=S_IFREG|0640, st_size=3, ...}) = 0 | |
ioctl(12, TCGETS, 0x3fffed9c8200) = -1 ENOTTY (Inappropriate ioctl for device) | |
lseek(12, 0, SEEK_CUR) = 0 | |
ioctl(12, TCGETS, 0x3fffed9c8170) = -1 ENOTTY (Inappropriate ioctl for device) | |
lseek(12, 0, SEEK_CUR) = 0 | |
lseek(12, 0, SEEK_CUR) = 0 | |
fstat(12, {st_mode=S_IFREG|0640, st_size=3, ...}) = 0 | |
read(12, "{}\n", 4) = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_data(files, total_records): | |
records = [] | |
while len(records) < total_records: | |
# Rotate the files queue | |
files.rotate(1) | |
with open(files[0]) as handle: | |
data = json.load(handle) | |
for record in data: | |
records.append(record) | |
If len(records) >= total_records: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import func, select, Column, ForeignKey, Integer, String, create_engine | |
from sqlalchemy.orm import sessionmaker, relationship | |
from sqlalchemy.sql.expression import literal_column | |
from sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base() | |
engine = create_engine('postgresql+psycopg2://postgres:password@localhost/test', echo=True) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
krace@hotbox /m/u/code> cat json_pg.py | |
import psycopg2 | |
def run(stmt): | |
cur = psycopg2.connect(database='test', user='postgres', password='password', host='localhost').cursor() | |
cur.execute(stmt) | |
result = cur.fetchall() | |
print(list(result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
krace@hotbox /m/u/code> cat json_pg.py | |
import psycopg2 | |
def run(stmt): | |
cur = psycopg2.connect(database='test', user='postgres', password='password', host='localhost').cursor() | |
cur.execute(stmt) | |
result = cur.fetchall() | |
print(list(result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test=# select row_to_json(row) from (select book.id, book.name, book.author_id, author.name as author_name from book inner join author on book.author_id = author.id) row; | |
{"id":1,"name":"War and Peace","author_id":1,"author_name":"Leo Tolstoy"} | |
{"id":2,"name":"The Trial","author_id":2,"author_name":"Kafka"} | |
{"id":3,"name":"The metamorphosis","author_id":2,"author_name":"Kafka"} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test=# select row_to_json(author) from author; | |
{"id":1,"name":"Leo Tolstoy"} | |
{"id":2,"name":"Kafka"} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE author ( | |
id INTEGER NOT NULL, | |
name VARCHAR(255) NOT NULL, | |
PRIMARY KEY (id) | |
); | |
CREATE TABLE book ( | |
id INTEGER NOT NULL, | |
name VARCHAR(255) NOT NULL, | |
author_id INTEGER, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', ../src/libcore/option.rs:323 | |
stack backtrace: | |
1: 0x55e4e99bd5ff - std::sys::backtrace::tracing::imp::write::h6f1d53a70916b90d | |
2: 0x55e4e99c00ad - std::panicking::default_hook::{{closure}}::h137e876f7d3b5850 | |
3: 0x55e4e99bf60a - std::panicking::default_hook::h0ac3811ec7cee78c | |
4: 0x55e4e99bfb58 - std::panicking::rust_panic_with_hook::hc303199e04562edf | |
5: 0x55e4e99bf9f2 - std::panicking::begin_panic::h6ed03353807cf54d | |
6: 0x55e4e99bf930 - std::panicking::begin_panic_fmt::hc321cece241bb2f5 | |
7: 0x55e4e99bf8b1 - rust_begin_unwind | |
8: 0x55e4e99f4b1f - core::panicking::panic_fmt::h27224b181f9f037f |