Skip to content

Instantly share code, notes, and snippets.

View nitely's full-sized avatar
🟢
online

Esteban C Borsani nitely

🟢
online
View GitHub Profile
@nitely
nitely / nm-resume.service
Created October 23, 2015 00:14
Ubuntu +15.04 systemd restart network after resume
# sudo nano /lib/systemd/system/nm-resume.service
# sudo systemctl enable nm-resume.service
[Unit]
Description=Restart NetworkManager at resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target
[Service]
ExecStart=/bin/systemctl --no-block restart NetworkManager.service
@nitely
nitely / merge.py
Last active November 29, 2015 19:37
Merge dicts
# Untested
def merge(dict_a, dict_b, **kwargs):
assert isinstance(dict_a, dict), \
"A dict was expected in %s" % kwargs.pop('node_name', 'first param')
for k, v in dict_b.items():
if isinstance(v, dict):
merge(dict_a.setdefault(k, {}), v, node_name=k)
continue
@nitely
nitely / raw_server.py
Last active December 18, 2015 23:17
Python asyncio server (for benchmarking raw asyncio performance)
import asyncio
@asyncio.coroutine
def read_header(reader):
while True:
try:
data = yield from reader.readline()
except ConnectionResetError:
return
@nitely
nitely / fp.py
Created December 26, 2015 04:55
Python function composition/pipelining
def compose(*funcs):
"""
Compose N functions into one.\
The returned values for a function\
are the received parameters for the next function
Usage::
def parse(request_line_raw):
parser = compose(
@nitely
nitely / ab.py
Created January 2, 2016 10:31
Topcoder AB problem
"""
Problem Statement
You are given two s: N and K. Lun the dog is interested in strings that satisfy the following conditions:
The string has exactly N characters, each of which is either 'A' or 'B'.
The string s has exactly K pairs (i, j) (0 <= i < j <= N-1) such that s[i] = 'A' and s[j] = 'B'.
If there exists a string that satisfies the conditions, find and return any such string. Otherwise, return an empty string.
Definition
@nitely
nitely / abab.py
Created January 4, 2016 04:10
Topcoder ABAB problem
"""
Problem Statement
One day, Jamie noticed that many English words only use the letters A and B. Examples of such words include "AB" (short for abdominal), "BAA" (the noise a sheep makes), "AA" (a type of lava), and "ABBA" (a Swedish pop sensation).
Inspired by this observation, Jamie created a simple game. You are given two s: initial and target. The goal of the game is to find a sequence of valid moves that will change initial into target. There are two types of valid moves:
Add the letter A to the end of the string.
Reverse the string and then add the letter B to the end of the string.
@nitely
nitely / child_app_apps.py
Created January 31, 2016 17:07
Haystack extend index
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class ChildAppConfig(AppConfig):
name = 'child_app'
@nitely
nitely / sanitize_url.py
Last active February 26, 2016 02:43
URL Sanitizer
SAFE_PROTOCOLS = {'http', 'https'}
def escape(text):
return (text
.replace('&', '&amp;')
.replace('<', '&lt;')
.replace('>', '&gt;')
.replace('"', '&quot;')
.replace("'", '&#39;'))
@nitely
nitely / v8-versions.md
Created April 7, 2016 20:12 — forked from domenic/v8-versions.md
V8 versions for embedders

Embedders of V8 should generally use the head of the branch corresponding to the minor version of V8 that ships in Chrome.

Finding the minor version of V8 corresponding to the latest stable Chrome

To find out what version this is,

  1. Go to https://omahaproxy.appspot.com/
  2. Find the latest stable Chrome version in the table
  3. Enter it into the "Translate a Chrome verison to a V8 version" box below the table.
  4. Ignore the last two parts.
@nitely
nitely / duplicated_files_finder.py
Last active August 27, 2017 19:53
Duplicated Files Finder
# -*- coding: utf-8 -*-
"""
Tested on python 3.5
Duplicated Files Finder
-----------------------
This skips files with a unique size, then group by size\
and does chunk-by-chunk (bytes-by-bytes) comparison to\