Skip to content

Instantly share code, notes, and snippets.

View naufraghi's full-sized avatar

Matteo Bertini naufraghi

View GitHub Profile
@naufraghi
naufraghi / justfile
Last active October 18, 2019 07:20
Home directory justfile
list:
@just --list
# Optimize PDF file
pdfoptimize SOURCE:
cp "{{SOURCE}}" "{{SOURCE}}.bak"
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="{{SOURCE}}" "{{SOURCE}}.bak"
ls -lah "{{SOURCE}}" "{{SOURCE}}.bak"
# Move to PROJECT dev folder (and environment)
class Checked(object):
"""
This class offers a `checked()` method that returns the same namedtuple after an user defined check.
The returned class is not exacly the same, but is in fact a copy with an added marker base class.
Given the `namedtuple` immutability, the marker base class is used to skip the checks after the first run.
"""
class Done: # Using `Done(object)` let the code work as expected in Python 2 too
__slots__ = ()
@naufraghi
naufraghi / somewhat_safer_unpickler.py
Last active August 22, 2018 12:25
Somewhat safer unpickler, only builtins (/usr/lib/python2.7/pickle.py)
# #######################################################################
# Somewhat safer unpickler, only builtins (/usr/lib/python2.7/pickle.py)
# #######################################################################
class LimitedUnpickler(pickle.Unpickler):
"""
This class inherits all the implementation from the builtin
`pickle.Unpickler` but modifies the `self.dispatch` dictionary
used to unpack the serialized structures.
"""distutils.msvc9compiler
Contains MSVCCompiler, an implementation of the abstract CCompiler class
for the Microsoft Visual Studio 2008.
The module is compatible with VS 2005 and VS 2008. You can find legacy support
for older versions of VS in distutils.msvccompiler.
"""
# Written by Perry Stoll
@naufraghi
naufraghi / errlog.go
Created October 17, 2016 12:59
Spawn a samename process and capture stderr to file
package main
import (
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
@naufraghi
naufraghi / trie.py
Last active October 17, 2016 12:57
Prefix tree implementation in Python 3, based on `dict`
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from typing import Sequence, Union
# Does not typecheck yet because of the hardcoded slice int types
class KeyErrorWithChildren(KeyError):
pass
TrieKey = Union[Sequence,slice]

elm-package-search

This script is a simple jq wrapper to search Elm packages.

Elm packages use the pattern <username>/<packagename> but for me is quite usual to remember only the package name.

This is a fast and dirty solution built upon the fantastic jq tool.

Analytics

from PyQt4.Qt import *
def teeSignal(*sig_args, **kwargs):
if "name" not in kwargs:
raise ValueError("Signal name required for old style emit compatibility")
class X(QObject):
signal = pyqtSignal(*sig_args, **kwargs)
x = X()
sig_name = kwargs["name"]
has_args = len(sig_args) > 0
@naufraghi
naufraghi / keybase.md
Created September 18, 2014 09:42
Keybase proof

Keybase proof

I hereby claim:

  • I am naufraghi on github.
  • I am naufraghi (https://keybase.io/naufraghi) on keybase.
  • I have a public key whose fingerprint is C01B A13F 5190 29A7 82E1 975A C4D1 A495 B316 6AF3

To claim this, I am signing this object:

@naufraghi
naufraghi / android_sdk.yml
Created August 8, 2014 07:23
Ansible Playbook for Android SDK + gradle on c9.io
---
- hosts: local
sudo: yes
vars:
home: "{{ lookup('env','HOME') }}"
tasks:
- name: enable multiarch
command: dpkg --add-architecture i386
- name: install deps
apt: name={{ item }} update_cache=yes cache_valid_time=3600