Skip to content

Instantly share code, notes, and snippets.

@viyatb
viyatb / translate.py
Created August 29, 2013 10:27
A script to use Google Translate more efficiently
#!/usr/bin/env python
import sys
import json
import urllib
import urllib2
import argparse
def translate(target, text):
api = "https://www.googleapis.com/language/translate/v2?"
api_key = "AIzaSyBgBlJCogk_1Hd_7WaLQgLVbQss0_dvNUc"
@viyatb
viyatb / unix_to_msdos.py
Created August 29, 2013 11:35
Simple script to convert *nix text files to MS-DOS format.
import sys
def convert(format, fname):
for line in open(fname, 'rb').readlines():
if format == 'todos':
if line[-1:]=='\n' and line[-2:-1] !='\r':
line=line[-1:]='\r\n'
elif format == 'tolinux':
if line[-2:]=='\r\n':
@viyatb
viyatb / dicfield_django.md
Last active December 31, 2015 01:28
Use DictField() in Django admin [Django-nonrel]
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@viyatb
viyatb / app.py
Created March 19, 2014 13:38 — forked from ayang/app.py
class Application(tornado.web.Application):
def __init__(self):
tornado.web.Application.__init__(self, handlers, **settings)
self.db_session = db_session
self.redis = redis.StrictRedis()
self.session_store = RedisSessionStore(self.redis)
class BaseHandler(tornado.web.RequestHandler):
@viyatb
viyatb / cookie.py
Created March 19, 2014 13:42
Cookie handling in Tornado
@viyatb
viyatb / session.py
Created March 19, 2014 13:48
Session Handling in Tornado thanks to @milan Cermak
# -*- coding: utf-8 -*-
"""
Sessions module for the Tornado framework.
Milan Cermak <milan.cermak@gmail.com>
This module implements sessions for Tornado. It can store
session data in files or MySQL databse, Memcached, Redis
and MongoDB.
@viyatb
viyatb / pre-commit
Last active August 29, 2015 13:57
PEP8 p re-commit hook for OWTF
#!/bin/sh
# Auto-check for pep8 and flake8 proposed formatting checks automatically before committing bad code
# requires flake8 module
# The following is a list of the most common PEP 8 errors and warnings; to
# skip some just add them to the IGNORE variable (comma separated):
# E111 indentation is not a multiple of four
# E123 closing bracket does not match indentation of opening bracket's line
# E201 whitespace after '('
# E202 whitespace before ')'