Skip to content

Instantly share code, notes, and snippets.

View flaschbier's full-sized avatar
🐢
feeling turty when decelerated by Java

flaschbier

🐢
feeling turty when decelerated by Java
View GitHub Profile
drop table "DB1";
create table "DB1" (
lid integer,
pid integer,
"Date" date,
primary key (lid)
);
insert into "DB1"(lid, pid, "Date")

If the file you are showing us is really huge, you will not be able to read it right away via the json module like so:

with open('users.txt') as f:    
    users = json.load(f)

Your impression of huge, however, may be different from the impression your computer has, so give it a try even if it's a few thousands of users in your file.

Now for the huge case. Here one big read will not be possible and you have to process the data line by line. Parsing JSON yourself is not a good idea, but when you rely on certain patterns that your input data show, you can write a simple iteration that will process each user block individually:

import json

@flaschbier
flaschbier / q35248610.py
Last active February 7, 2016 15:41
Fiddling with regex select to multi valued attributes in MongoDB. Working fine with Python 2.7.6 and PyMongo 3.2.1
#!/usr/bin/env python
# encoding: utf-8
"""
http://stackoverflow.com/questions/35248610
how to “find” docs in mongodb (in python) where a substring exists in a field
which is a list of strings? [no duplicate]
"""
import json
@flaschbier
flaschbier / flask_auf_uberspace.markdown
Last active December 29, 2019 17:55
Anleitung für Flask auf Uberspace.

Was ist das hier?

Gestartet ist dieser Gist als lesbare (Markdown-) Version des leider schwer lesbaren Gists von dAnjou vom Januar 2015, der aus dem Uberspace-Wiki verlinkt ist. Jetzt allerdings, im Januar 2016, stellt sich heraus, dass diese Anleitung aus mehreren Gründen nicht mehr ohne weiteres funktioniert. Deswegen habe ich sie dem Stand der Erkenntnisse angepasst und überarbeitet. Dennoch meinen herzlichen Dank an dAnjou für den Kickstart, ohne den alles viel kniffliger gewesen wäre :3

Mit dem Flask-Framework entwickeln

Flask ist ein Micro-Framework für Webapplikationen auf Python-Basis. Und da Du in Deinem Uberspace selbst Python-Module installieren kannst, solltest Du auch Flask-Anwendungen im Uberspace laufen lassen können.

Trotz acht Jahren Python 3 und der [unerquicklichen Unicode-Behandlung von python 2](https://docs.pytho

#!/usr/bin/python -u
# encoding: UTF-8
import sqlite3
import argparse
from datetime import datetime
DBFILE = 'nested.sqlite'
MAX_A = 1000
MAX_B = 10000
@flaschbier
flaschbier / mkpycurl.py
Last active April 18, 2019 21:50
Automates compiling a python-pycurl version with openssl instead of GnuTLS for Ubuntu and Raspbian following the recipe in Gist https://gist.github.com/aerickson/f15133a7e56b2d7f27e3. See this answer http://askubuntu.com/a/666868/184228 on Ask Ubuntu for details.
#!/bin/bash
#
# How to rebuild PycURL against OpenSSL on Ubuntu
# (tested for 14.04.2 now)
#
# This script implements the great Gist by aerickson:
# https://gist.github.com/aerickson/f15133a7e56b2d7f27e3
# feel free to use it anyway you like.
# Credits go to Andrew anyway :)