Skip to content

Instantly share code, notes, and snippets.

Flávio Juvenal da Silva Junior fjsj

Block or report user

Report or block fjsj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@simonw
simonw / recover_source_code.md
Last active Nov 13, 2019
How to recover lost Python source code if it's still resident in-memory
View recover_source_code.md

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@pjbull
pjbull / SparseInteractions.py
Last active Jun 26, 2019
Sparse Interaction Terms for scikit-learn
View SparseInteractions.py
from sklearn.base import BaseEstimator, TransformerMixin
from scipy import sparse
from itertools import combinations
class SparseInteractions(BaseEstimator, TransformerMixin):
def __init__(self, degree=2, feature_name_separator="_"):
self.degree = degree
self.feature_name_separator = feature_name_separator
@GitRay
GitRay / serialize.py
Last active May 24, 2019 — forked from mrocklin/serialize.py
Serialization benchmark
View serialize.py
# This has been edited to work with python3. Some of the tested combinations will not work in python2.
import pandas as pd
df = pd.DataFrame({'text': [str(i % 1000) for i in range(1000000)],
'numbers': range(1000000)})
import pickle
# Python 3 has no cPickle
#import cPickle
import json
from functools import partial
@bofm
bofm / escape_xml.py
Last active Jul 30, 2019
Escape invalid XML characters in Python 3
View escape_xml.py
#!/usr/bin/env python3
import sys
import re
# https://trac-hacks.org/ticket/11050#comment:13
_illegal_unichrs = ((0x00, 0x08), (0x0B, 0x1F), (0x7F, 0x84), (0x86, 0x9F),
(0xD800, 0xDFFF), (0xFDD0, 0xFDDF), (0xFFFE, 0xFFFF),
(0x1FFFE, 0x1FFFF), (0x2FFFE, 0x2FFFF),
(0x3FFFE, 0x3FFFF), (0x4FFFE, 0x4FFFF),
@superdaigo
superdaigo / tasks.py
Created Apr 22, 2016
Celery rate_limit test script
View tasks.py
"""
# Test celery's rate_limit
Tested version of python
$ python --version
Python 2.7.11
## Requirements
$ pip install celery==3.1.23
$ pip install SQLAlchemy==1.0.12
@kristopolous
kristopolous / hn_seach.js
Last active Nov 5, 2019
hn job query search
View hn_seach.js
function query() {
var
// HN is done with very unsemantic classes.
job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.cae,.c00,.c9c,.cdd,.c73,.c88')),
query_list = Array.prototype.slice.call(arguments),
shown = 0, total = job_list.length;
// Traverses up the dom stack trying to find a match of a specific class
function up_to(node, klass) {
if (node.classList.contains(klass)) {
@nealtodd
nealtodd / gist:a8f87b0d95e73eb482c5
Created Jun 10, 2015
Django management command to detect missing migration files.
View gist:a8f87b0d95e73eb482c5
import sys
from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import connections
from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.state import ProjectState
from django.db.utils import OperationalError
@itamarhaber
itamarhaber / 00_copy_key.lua
Last active Oct 11, 2019
The fastest, type-agnostic way to copy a Redis key, as discussed in https://redislabs.com/blog/the-7th-principle-of-redis-we-optimize-for-joy
View 00_copy_key.lua
-- @desc: The fastest, type-agnostic way to copy a Redis key
-- @usage: redis-cli --eval copy_key.lua <source> <dest> , [NX]
local s = KEYS[1]
local d = KEYS[2]
if redis.call("EXISTS", d) == 1 then
if type(ARGV[1]) == "string" and ARGV[1]:upper() == "NX" then
return nil
else
@econandrew
econandrew / NominatimOnEC2.md
Last active Apr 13, 2019
Instructions for installing an OpenStreetMap Nominatim geocoder instance on Amazon Linux / EC2 (Dec 2014)
View NominatimOnEC2.md

Installing Nominatim on Amazon Linux / EC2

  1. Introduction

The official instructions for installing Nominatim are complete, but brief in places, and several steps must be changed in the Amazon Linux environment (which is roughly CentOS / Redhat). The steps below are rough record of what I did to get it working, but I didn't keep perfect track so you shouldn't rely on them as a shell script. Just follow each step, make sure it worked, and hopefully you'll need to adapt very little (version numbers, for one thing). (I also skip in and out of root, but you can be more careful if you like.)

  1. Setting up the EC2 instance

@jacoor
jacoor / AdditionalDataListApiView.py
Created Mar 5, 2014
additional data for listApiView for django.rest.framework
View AdditionalDataListApiView.py
class TransactionsList(ListAPIView):
"""
List all transactions for currently logged in user, paginated by 25
page -- page number
ordering -- yoddle_amount, created, yoddle_description, reverse order ie. -yoddle_amount
"""
model = Transaction
You can’t perform that action at this time.