Skip to content

Instantly share code, notes, and snippets.

View nZac's full-sized avatar

Nick Zaccardi nZac

View GitHub Profile
@nZac
nZac / app.py
Last active March 20, 2017 21:36
import flask
import socket
import fcntl
import struct
app = flask.Flask(__name__)
# http://stackoverflow.com/questions/24196932/how-can-i-get-the-ip-address-of-eth0-in-python
def get_ip_address(ifname):
@nZac
nZac / release.sh
Last active December 15, 2016 16:55
Release PyPI Project
#!/bin/bash -e
#
# Author: Nick Zaccardi <nick.zaccardi@level12.io>
#
# This script is designed to help release packages to PyPI faster. It tries its
# best to walk you through all the steps to release a source packages and a
# binary wheel package.
#
# The script does the following
#
-- Compile to app.js
import Html exposing (Html, button, div, text)
import Html.App as App
import Html.Events exposing (onClick)
main =
App.beginnerProgram { model = 0, view = view, update = update }
type Msg = Increment | Decrement

Keybase proof

I hereby claim:

  • I am nZac on github.
  • I am nzac (https://keybase.io/nzac) on keybase.
  • I have a public key whose fingerprint is 7794 2275 099A 5790 621C 880D 8E9A C0F5 5EB1 256B

To claim this, I am signing this object:

@nZac
nZac / TempDropFKContraint.py
Last active November 26, 2020 20:21
Temporarily Drop a Foreign Key Constraint, Python, SQLAlchemy
class TempDropConstraint(object):
def __init__(self, table, column):
self.table = table
self.table_name = table.__tablename__
self.column = column
self.constraint = list(self.table.__table__.columns[column.name].foreign_keys)[0]
self.constraint_name = self.constraint.name
self.referred_table = self.constraint.column.table.name
@nZac
nZac / sqlalchemy_debugger.py
Last active April 16, 2019 13:07
SQLAlchemy query to compiled SQL string
try:
import sqlparse.format as sqlformat
except ImportError:
def sqlformat(query, **kwargs):
"""Monkey patch sqlparse.format if package not installed"""
return query
def debug_query(query, engine):
"""Return a parametrized and formated sql query for debugging
-- Create a list of dates incremented by month
DECLARE @MinDate DATE = '20120101',
@MaxDate DATE = '20150101';
SELECT TOP (DATEDIFF(MONTH, @MinDate, @MaxDate) + 1)
full_date = DATEADD(MONTH, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, @MinDate)
FROM sys.all_objects a
CROSS JOIN sys.all_objects b
import os
from os import path as osp
import sys
import keyring
paths_to_link = (
'/usr/lib/python2.7/dist-packages/dbus',
'/usr/lib/python2.7/dist-packages/_dbus_bindings.so',
'/usr/lib/python2.7/dist-packages/_dbus_glib_bindings.so',
>>> d = ["25","30","35","40","100","10000","1000000000"]
>>> c = [25,30,35,40,100,10000,1000000000]
>>> sorted(d).pop()
'40'
>>> sorted(c).pop()
1000000000
@nZac
nZac / gosqrt.go
Last active August 29, 2015 13:56
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) (float64, int) {
z := float64(x)