Skip to content

Instantly share code, notes, and snippets.

View tinnet's full-sized avatar
🐼

Martin Contento tinnet

🐼
View GitHub Profile
@tinnet
tinnet / Vagrantfile
Created June 19, 2013 22:16
'basic' Vagrantfile
# -*- mode: ruby -*-
# # vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.ssh.forward_agent = true
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 512]
cursor = db.connection.cursor()
# borrowed from http://goo.gl/BWxNj
seq_fix_sql = """SELECT setval('django_messages_message_id_seq', coalesce((select max(id)+1 from django_messages_message), 1), true)"""
cursor.execute(seq_fix_sql)
# download GeoIPCity.dat from http://dev.maxmind.com/geoip/geolite
# pip install pygeoip
# get ip list eg. from sshguard logs:
# zgrep Blocking /var/log/auth.log* | cut -d ' ' -f 7 | cut -d ':' -f 1 | sort -u > ips.txt
# python geoiplookup.py ips.txt (or directly cat)
import fileinput
import sys
import pygeoip
-- query existing row with int (gets worse with amount of rows)
CREATE TABLE `identity` (
`provider_name` varchar(256) NOT NULL,
`provider_user_id` varchar(256) NOT NULL,
`uuid` char(32) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`provider_name`,`provider_user_id`),
KEY `uuid` (`uuid`),
CONSTRAINT `identity_ibfk_1` FOREIGN KEY (`uuid`) REFERENCES `global_user` (`uuid`)
<?php
phpinfo();
@tinnet
tinnet / app.yaml
Last active December 13, 2015 17:59
application: GAE_APP_IDENTIFIER
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: main.app
def wrap_list_in_result_dict(entities, page=1, total_pages=1, num_results=None):
return dict(
entities=entities,
page=page,
total_pages=total_pages,
num_results=num_results or len(entities))
# this is the entire list
print wrap_list_in_result_dict([1,2,3,4])
from __future__ import print_function
import argparse
import csv
import sys
_EPILOG = """
"""
if __name__ == '__main__':
@tinnet
tinnet / urlchecker.py
Created January 10, 2013 11:11
Small python (2.7) script to check .csv files full of urls for their current status code (for example to verify if you fixed the issues google webmaster tools is reporting)
from __future__ import print_function
import argparse
import csv
import requests
import sys
_EPILOG = """
Script takes a list of .csv files, tries to guess their format (seperator),
then checks for a field called 'URL', tries to fetch that url and prints
@tinnet
tinnet / flaskrouting.py
Created November 12, 2012 13:42
flask extension pluggable views routing errors
import flask
import flask.views
import logging
logging.basicConfig(level=logging.DEBUG)
class MyFlaskExt(object):
def __init__(self, app=None):
if app is not None:
self.init_app(app)