Skip to content

Instantly share code, notes, and snippets.

View anderser's full-sized avatar

Anders Eriksen anderser

View GitHub Profile
@anderser
anderser / grabber.py
Created May 22, 2012 18:13
Grab webpage from python/django with wkhtmltopdf
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import shlex, subprocess
import logging
from django.conf import settings
logger = logging.getLogger('pagetracker.grabber')
def grab_page(url, outfile):
@anderser
anderser / views.py
Created September 28, 2012 12:27
Presidentpoll - get data fra HuffPost president pollofpoll and pass to Django template
from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
from django.http import HttpResponseRedirect, Http404, HttpResponse
from django.template import RequestContext
from django.core.cache import cache
import iso8601
from pollster import Pollster
def presidentmatch(request):
@anderser
anderser / articleanalytics.py
Created November 15, 2012 21:16
Get Google analytics metrics for single url/article
from local_settings import GOOGLE_USER, GOOGLE_PWD
from googleanalytics import Connection
from datetime import date
#googleanalytics is found here: https://github.com/clintecker/python-googleanalytics/
gaaccounts = {
'myaccountname': '1234567',
}
@anderser
anderser / app.py
Last active December 18, 2015 19:49
Retrieve video urls from Instagram API using instagram python client. Has to use the raw json response since the python client does not yet support video.
api = client.InstagramAPI(client_id=CONFIG['client_id'], client_secret=CONFIG['client_secret'])
instagen, pages = api.tag_recent_media(30, 0, "thetag", max_pages=1, return_json=True)
videos = []
for item in instagen:
if "videos" in item:
videos.append(
{'user': item['user']['username'],
'videourl': item['videos']['standard_resolution']
@anderser
anderser / convert.py
Last active January 3, 2024 08:52
Convert from NodeXL (via GraphML-format) to D3-ready json for force layout while adding modularity groups (communities) as attribute to nodes. Useful for coloring nodes via modularitygroup attribute. Requires networkx and python-louvain. First export as GraphML file from your NodeXL-sheet. Then run: >>> python convert.py -i mygraph.graphml -o ou…
#!/usr/bin/env python
import sys
import argparse
import networkx as nx
import community
from networkx.readwrite import json_graph
def graphmltojson(graphfile, outfile):
@anderser
anderser / esi.py
Created February 21, 2014 14:05
Django template tag for simulating ESI rendering on dev and rendering ESI tags in production. Use ESI_ON=True to render locally.
from django import template
from django.test.client import Client
from django.conf import settings
from django.core.cache import cache
from django.utils.hashcompat import md5_constructor
register = template.Library()
@register.simple_tag
def esi(url, timeout=10):
@anderser
anderser / kommunebygger.css
Last active August 29, 2015 14:05
CartoCSS for kommunekart med navn på kommuner
Map {
background-color: #ffffff;
}
#kommuner {
polygon-fill: #e8e4e4;
polygon-opacity: 1;
line-color: #a1a1a1;
line-width: 0.5;
}
@anderser
anderser / kommuner_med_hav.topojson
Last active May 26, 2019 15:46
Node.js script for å finne nabokommuner fra en topojson-fil med kommunegrenser. Brukt i #kommunebygger
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@anderser
anderser / storkommune.sql
Last active August 29, 2015 14:06
Slå sammen kommuner i SQL
SELECT ST_Multi(ST_UNION(ST_MakeValid(k.the_geom))) FROM norske_kommuner k WHERE nr IN ('1201', '1247', '1243')
@anderser
anderser / component.css
Created December 10, 2014 13:32
Stacked
.stack {
margin: 20px auto;
width: 400px;
padding: 0;
position: relative;
max-width: 100%;
}
.stack div {
max-width: 100%;