Skip to content

Instantly share code, notes, and snippets.

Avatar

Marcio Mazza marciomazza

View GitHub Profile
@knowsuchagency
knowsuchagency / typecheck.py
Last active Feb 6, 2022
A cell magic to enable the use of mypy within jupyter notebooks
View typecheck.py
"""
Add mypy type-checking cell magic to jupyter/ipython.
Save this script to your ipython profile's startup directory.
IPython's directories can be found via `ipython locate [profile]` to find the current ipython directory and ipython profile directory, respectively.
For example, this file could exist on a path like this on mac:
/Users/yourusername/.ipython/profile_default/startup/typecheck.py
@muendelezaji
muendelezaji / bash-to-zsh-hist.py
Created Oct 5, 2016 — forked from op/bash-history-to-zsh-history.py
Convert Bash history to Zsh history
View bash-to-zsh-hist.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This is how I used it:
# $ cat ~/.bash_history | python bash-to-zsh-hist.py >> ~/.zsh_history
import sys
import time
@oinopion
oinopion / read-access.sql
Created Oct 5, 2016
How to create read only user in PostgreSQL
View read-access.sql
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@huytd
huytd / .gitconfig
Created Aug 4, 2016
Use neovim as diff tool
View .gitconfig
[merge]
tool = vimdiff
[mergetool]
prompt = true
[mergetool "vimdiff"]
cmd = nvim -d $LOCAL $REMOTE $MERGED -c '$wincmd w' -c 'wincmd J'
[difftool]
prompt = false
[diff]
tool = vimdiff
@magopian
magopian / conftest.py
Last active Nov 1, 2018
Some pytest(-django) fixtures that I find useful. There's also an "app" fixture to take advantage of django-webtest when used with py.test.
View conftest.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, division
import pytest
from django_webtest import DjangoTestApp, WebTestMixin
class Stub(object):
"""Stub methods, keep track of calls."""
@mattratleph
mattratleph / vimdiff.md
Last active Jun 23, 2022 — forked from roothybrid7/vimdiff_cheet.md
vimdiff cheat sheet
View vimdiff.md

vimdiff cheat sheet

##git mergetool

In the middle file (future merged file), you can navigate between conflicts with ]c and [c.

Choose which version you want to keep with :diffget //2 or :diffget //3 (the //2 and //3 are unique identifiers for the target/master copy and the merge/branch copy file names).

:diffupdate (to remove leftover spacing issues)

:only (once you’re done reviewing all conflicts, this shows only the middle/merged file)

@marciomazza
marciomazza / stripbuildoutcache.py
Created Jul 9, 2012
Strips the buildout cache from older egg versions
View stripbuildoutcache.py
#!/usr/bin/python
import os
from itertools import groupby
from shutil import rmtree
from pkg_resources import parse_version
def main():
"""Strips the buildout cache from older egg versions
@nicferrier
nicferrier / gist:2277987
Created Apr 1, 2012
Clone a git repo if it does not exist, or pull into it if it does exist
View gist:2277987
#!/bin/sh
REPOSRC=$1
LOCALREPO=$2
# We do it this way so that we can abstract if from just git later on
LOCALREPO_VC_DIR=$LOCALREPO/.git
if [ ! -d $LOCALREPO_VC_DIR ]
then
@perrygeo
perrygeo / gist:1903033
Created Feb 24, 2012
Sed scripts to fix blank lines and whitespace; helps code comply with PEP8
View gist:1903033
# Removes whitespace chars from blank lines
pep8 -r --select=W293 -q --filename=*.py /usr/local/src/madrona/madrona/ | xargs sed -i 's/^[ \r\t]*$//'
# Removes trailing blank lines from files
pep8 -r --select=W391 -q --filename=*.py /usr/local/src/madrona/madrona/ | xargs sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}'
# Squashes consecutive blanks lines into one
pep8 -r --select=E303 -q --filename=*.py /usr/local/src/madrona/madrona/ | xargs sed -i '/./,/^$/!d'
# confirm
@mitchellrj
mitchellrj / configure.zcml
Created Nov 25, 2011
z3c.form data manager for persistent dictionaries
View configure.zcml
<configure
xmlns="http://namespaces.zope.org/zope">
<adapter
factory=".datamanager.PersistentDictionaryField" />
</configure>