Skip to content

Instantly share code, notes, and snippets.

@podhmo
podhmo / result
Created July 17, 2012 19:50
how to use session.merge [sqlalchemy]
[<__main__.Sub object at 0x1f44250>, <__main__.Sub object at 0x1f44390>, <__main__.Sub object at 0x1f44350>]
[u'a', u'b', u'c']
pre commit
------
ok
after commit
------
@szs8
szs8 / pandasgrid.py
Created September 7, 2012 21:12
Display a pandas dataframe in a wx grid
#!/usr/bin/env python
import wx
from wx import EVT_CLOSE
import wx.grid as gridlib
EVEN_ROW_COLOUR = '#CCE6FF'
GRID_LINE_COLOUR = '#ccc'
class PandasTable(wx.Frame):
@cmslewis
cmslewis / sort.c
Created February 3, 2013 09:30
A few simple sorting algorithms
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* ==========================================================================
* COMPARATORS
* ========================================================================== */
@tsiege
tsiege / The Technical Interview Cheat Sheet.md
Last active April 20, 2024 16:52
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

ANNOUNCEMENT

I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!






\

@aldraco
aldraco / gist:15236a4dfaf76e866fc0
Created September 28, 2015 16:28
Learning Python - class for Rational numbers, inspired by interactivepython.org's exercises.
def gcd(m,n):
while m % n != 0:
oldm = m
oldn = n
m = oldn
n = oldm % oldn
return n
class Rational:
def __init__(self, n, d):
@DaniSancas
DaniSancas / neo4j_cypher_cheatsheet.md
Created June 14, 2016 23:52
Neo4j's Cypher queries cheatsheet

Neo4j Tutorial

Fundamentals

Store any kind of data using the following graph concepts:

  • Node: Graph data records
  • Relationship: Connect nodes (has direction and a type)
  • Property: Stores data in key-value pair in nodes and relationships
  • Label: Groups nodes and relationships (optional)
@malexer
malexer / sqlalchemy_upsert.py
Last active January 26, 2024 14:09
Modelling UPSERT in SQLAlchemy (well actually it is not upsert but speed improvement is significant in comparison with simple session.merge)
# Note: it is a copy of great answer by "mgoldwasser" from Stackoverflow
# Check the original answer here: http://stackoverflow.com/a/26018934/1032439
# Imagine that post1, post5, and post1000 are posts objects with ids 1, 5 and 1000 respectively
# The goal is to "upsert" these posts.
# we initialize a dict which maps id to the post object
my_new_posts = {1: post1, 5: post5, 1000: post1000}
for each in posts.query.filter(posts.id.in_(my_new_posts.keys())).all():
@thomas-a-neil
thomas-a-neil / test_s3_download.py
Created August 22, 2016 20:59
Sample DAG to download from S3, sleep, and reupload
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.python_operator import PythonOperator
from datetime import datetime, timedelta
# default arguments for each task
default_args = {
'owner': 'nthomas',
@kdubovikov
kdubovikov / tensorflow_mnist.py
Created June 18, 2017 07:29
TensorFlow MNIST example
import numpy as np
import tensorflow as tf
from tensorflow.contrib import learn
from tensorflow.contrib.learn.python.learn.estimators import model_fn as model_fn_lib
tf.logging.set_verbosity(tf.logging.INFO)
def cnn_model_fn(features, labels, mode):
@uhho
uhho / pandas_s3_streaming.py
Last active December 2, 2022 18:57
Streaming pandas DataFrame to/from S3 with on-the-fly processing and GZIP compression
def s3_to_pandas(client, bucket, key, header=None):
# get key using boto3 client
obj = client.get_object(Bucket=bucket, Key=key)
gz = gzip.GzipFile(fileobj=obj['Body'])
# load stream directly to DF
return pd.read_csv(gz, header=header, dtype=str)
def s3_to_pandas_with_processing(client, bucket, key, header=None):