Skip to content

Instantly share code, notes, and snippets.

View jdowner's full-sized avatar

Joshua Downer jdowner

View GitHub Profile
@jdowner
jdowner / Description.md
Created August 15, 2018 13:44 — forked from juanje/Description.md
Limit Chrome from eating all the memory and CPU

I was tired of Chrome eating all my laptop resources so I decided to put some limit to it with cgroup.

As I was using Ubuntu 12.04 with support for cgroup, I installed the package cgroup-bin and add the following group to the file /etc/cgconfig.conf:

group browsers {
    cpu {
#       Set the relative share of CPU resources equal to 25%
        cpu.shares = "256";
 }
@jdowner
jdowner / requirements.txt
Created December 24, 2017 11:31
url to text
docopt
readability-lxml
@jdowner
jdowner / unparse.py
Created January 15, 2017 10:23
python ast unparse
"Usage: unparse.py <path to source file>"
import sys
import ast
import cStringIO
import os
# Large float and imaginary literals get turned into infinities in the AST.
# We unparse those infinities to INFSTR.
INFSTR = "1e" + repr(sys.float_info.max_10_exp + 1)
@jdowner
jdowner / file1.txt
Created December 29, 2016 15:45
gpg public key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
mQINBFR1MNYBEACwF+IeDIXvKOWRHQrnuUD/OwEitWG1FgDJAe4M247pt0dkMhAP
SC14oXN57iDkjZ27W6YngSZyLDZLTvFOs4pzsSr80DB42NJo+K/TSHhtLx191O8b
gYBWERDXkBsd4lEwpWUsvc2gmJ+GrX2mQXejgDN1wbqECXi8nlGWztBOQVCXqid/
5nNWtOu/Hvr4MtxrOzyx7dmvz0A/tkpJ7m5K2gnxcEn9gxtjbgNOwsd/3yw36F7K
4YpSCMfx343xwieEmgfwncBI8uYBzOVHLcT2Ho6n+1RV8L3qMj33dNZiQ2T+u1uv
V+cvHRt9kqq+/o3LYkODNsBzVg8kJagZgiScWPqGFwxmS8+tiqfZeyYbWLPllG0N
5Dzo4Obx6PlO7FFyBpi18zIbmiykClUJysVIunNEG+Hb8/wE7vVjccG0SleWF8zJ
@jdowner
jdowner / .gitignore
Last active October 6, 2016 13:06
struct augmentation
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
@jdowner
jdowner / reqpro.py
Created April 28, 2016 10:58
requests-provides mechanism
import functools
import weakref
class Property(object):
instances = weakref.WeakValueDictionary()
def __new__(cls, name):
if name in Property.instances:
return Property.instances[name]
@jdowner
jdowner / input.py
Last active September 9, 2022 15:33
asyncio timed input
#!/usr/bin/env python3
"""
The MIT License (MIT)
Copyright (c) 2016 Joshua Downer
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
@jdowner
jdowner / sqlite2yaml.py
Last active November 14, 2023 13:23
Print a sqlite database file as YAML
#!/usr/bin/env python2
import argparse
import sys
import sqlalchemy
import yaml
def sqlite2yaml(filename):
@jdowner
jdowner / blocks.py
Created February 2, 2015 12:28
Iterator to return a sequence of blocks from an iterable
def blocks(iterable, n):
"""Create a generator that returns blocks of values
This generator yields lists of values from the iterable that contain 'n'
elements (except, possible, for the last block if the length of the iterable
is not divisible by 'n').
Arguments:
iterable: an interable object like a list or generator
n: a positive integer
@jdowner
jdowner / password_store.py
Last active August 29, 2015 14:14
Password retrieval from password-store or a custom store.
import collections
import os
import subprocess
class Entry(collections.namedtuple('Entry', 'username, password, url')):
"""
An Entry object represents an entry in the password store.
"""
def __new__(cls, username, password, url=None):
"""Create a new Entry object