Skip to content

Instantly share code, notes, and snippets.

View nZac's full-sized avatar

Nick Zaccardi nZac

View GitHub Profile
@nZac
nZac / max_int_in_dict.py
Created November 2, 2013 19:28
Find the largest int in a dictionary
print stats
# {'a': 3, 'c': 1, 'b': 8}
max(stats.iterkeys(), key=lambda key: stats[key])
# 'b'
# This is my personal zsh-theme file it requires oh-my-zsh and the
# wonderful virtualenv-prompt https://github.com/tonyseek/oh-my-zsh-virtualenv-prompt
# plugin
if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
CURRENT_TIME_=" %T%{$reset_color%}"
ZSH_THEME_VIRTUAL_ENV_PROMPT_PREFIX="$FG[237]-----$FG[075] ( venv: "
ZSH_THEME_VIRTUAL_ENV_PROMPT_SUFFIX="$FG[075] ) $FG[237]-----"
@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)
>>> d = ["25","30","35","40","100","10000","1000000000"]
>>> c = [25,30,35,40,100,10000,1000000000]
>>> sorted(d).pop()
'40'
>>> sorted(c).pop()
1000000000
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',
-- 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
@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
@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

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:

-- 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