Skip to content

Instantly share code, notes, and snippets.

# dict of conversion of google's charset to python codec name
enc_google_to_python = {
"windows-1257": "cp1257",
"GB2312 ": "gb2312",
"windows-874": "cp874",
"EUC-KR": "euc_kr",
"Shift_JIS": "shift_jis",
"UTF-8": "utf_8",
"ISO-8859-2": "iso8859_2",
"ISO-8859-9": "iso8859_9",
@mazieres
mazieres / ip2location.go
Created September 29, 2016 07:19
Lookup the location attributed to an IP by IP2Location Lite Country DB (https://lite.ip2location.com/database/ip-country)
package main
import (
"bufio"
"encoding/csv"
"errors"
"fmt"
"io"
"log"
"os"
@mazieres
mazieres / zb-data_collect.js
Created October 29, 2016 12:55
Zeitgeist Borders - Data Collection
function mkAllQueries(query) {
var allRes = {}
var promises = []
for (var i = 0; i < nb_hls; i++){
promises.push($.getJSON(apiUrl, {
"client": "firefox",
"hl": hls[i],
"q": query
})
.done(function (hl, q) {
import json
from json.decoder import WHITESPACE
def iterload(string, cls=json.JSONDecoder, **kwargs):
decoder = cls(**kwargs)
idx = WHITESPACE.match(string, 0).end()
while idx < len(string):
try:
obj, end = decoder.raw_decode(string, idx)
idx = WHITESPACE.match(string, end).end()

Keybase proof

I hereby claim:

  • I am mazieres on github.
  • I am mazieres (https://keybase.io/mazieres) on keybase.
  • I have a public key ASDzCRM2QkTnZ8Im0Yw210zPZZ54GykPj9xwJ6gw6bki0Qo

To claim this, I am signing this object:

import progressbar
i = 0
with progressbar.ProgressBar(max_value=len(entities)) as bar:
for entity in entities:
compute_metrics(entity)
i += 1
bar.update(i)
def flatten(li):
return [item for sublist in li for item in sublist]
@mazieres
mazieres / namograph.ipynb
Last active June 21, 2023 06:29
Python companion to the work described here : https://mazieres.gitlab.io/namograph/index.html
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am mazieres on github.
  • I am mazieres (https://keybase.io/mazieres) on keybase.
  • I have a public key whose fingerprint is 5C72 B759 A3D8 F135 0B23 A459 8356 48CC 0077 40FD

To claim this, I am signing this object:

#!/usr/bin/env python3
import subprocess
def cli(cmd_str):
process = subprocess.Popen(cmd_str, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
output, error = process.communicate()
output, error = [x if len(x) > 0 else None
for x in (output.decode().strip(), error.decode().strip())]