Skip to content

Instantly share code, notes, and snippets.

View mmas's full-sized avatar

Modesto Mas mmas

View GitHub Profile
#!/usr/bin/env python
import sys
for line in sys.stdin:
if line.startswith('"'):
index = line.find('"', 1)
fields = [line[1:index]]+line[index+2:].split(',')
else:
fields = line.split(',')
#!/usr/bin/env python
import sys
last_k = None
last_v = 0
for line in sys.stdin:
k, v = line.strip().split('\t')
#!/usr/bin/env python
import re
import sys
started = False
for line in sys.stdin:
if started:
#!/usr/bin/env python
import sys
last_k = None
max_v = 0
for line in sys.stdin:
k, v = line.strip().split('\t')
#!/usr/bin/env python
import sys
for line in sys.stdin:
if not line.strip() or line.startswith('Wban'):
continue
_, k, v = line[:17].split(',', 2)
try:
def get_visits(groupby):
ip_visits = data.groupby(groupby)['ip']
return pd.DataFrame(
{'unique_visits': ip_visits.apply(lambda x: len(set(x))),
'total_visits': ip_visits.apply(len)})
data['date_day'] = data['date'].apply(datetime.date)
visits_by_date = get_visits('date_day')
# Redefine with date index to avoid lack of dates.
visits_by_date = pd.DataFrame(visits_by_date,
from datetime import datetime, timedelta
import pandas as pd
source = pd.read_csv('data.csv', index_col='uuid', parse_dates=['date'])
date_1 = datetime.utcnow()
date_0 = date_1 - timedelta(days=30)
data = source[(source['date'] > date_0) & (source['date'] < date_1)]
import os
import json
from tornado.web import RequestHandler
from pygeoip import GeoIP
import dateutil.parser
from app.models import Visit
from app import settings
var data, ua, platform, browser, os;
data = {
page: window.location.pathname.replace(/\/$/, ''),
language: navigator.language.slice(0, 2).toUpperCase(),
screen_resolution: window.screen.width + 'x' + window.screen.height,
screen_dpi: window.devicePixelRatio,
is_touch_device: 'ontouchstart' in window || 'onmsgesturechange' in window
};
ua = navigator.userAgent.toLowerCase();
@mmas
mmas / translate.py
Last active October 11, 2016 11:00
Google translate client
#!/usr/bin/python
"""
Google translate client
usage: python translate.py [-h] [-v] [-ua User-Agent] source_lang target_lang text
positional arguments:
source_lang
target_lang