Skip to content

Instantly share code, notes, and snippets.

View kracekumar's full-sized avatar

Kracekumar kracekumar

View GitHub Profile
@kracekumar
kracekumar / shell_plus.py
Last active August 29, 2015 13:56
Django Reverse problem
In [2]: reverse('userbase.edit', kwargs={'id': 1})
Out[2]: '/userbase/1/edit/'
In [3]: reverse('userbase.delete', kwargs={'id': 1})
Out[3]: '/userbase/1/delete/'
In [4]: reverse('userbase.new')
Out[4]: '/userbase/new/'
In [5]: reverse('userbase.view', kwargs={'id': 1})
@kracekumar
kracekumar / forms.py
Created February 4, 2014 18:00
ModelForm and custom choices for field
# -*- coding: utf-8 -*-
from django.forms import ModelForm, TypedChoiceField
from .models import UserInfo
class UserInfoForm(ModelForm):
blood_group = TypedChoiceField(coerce=unicode)
gender = TypedChoiceField(coerce=int)
@kracekumar
kracekumar / flatten.py
Created March 12, 2014 19:07
Flatten nested data structure in python 3
from collections import Iterable
def flatten(items):
for item in items:
if isinstance(item, Iterable):
yield from flatten(item)
else:
yield item
nested = [1, 3, [3, [4, 5, [6]]]]
@kracekumar
kracekumar / init.el
Last active August 29, 2015 13:57
Emacs config
;; Steve yegge tips
;;; Replacement for using backspace
(global-set-key "\C-w" 'backward-kill-word)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-c\C-k" 'kill-region)
;; Full screen
(toggle-frame-fullscreen)
;; Remove Toolbar
(tool-bar-mode -1)
@kracekumar
kracekumar / sample.conf
Created April 15, 2014 18:32
Both selenium_001.py can be in directory. But sample.conf should be there in directory where the program is invoked.
[website]
url = http://www.python.org
@kracekumar
kracekumar / gist:36791f8a01ad33b5b9e5
Created May 15, 2014 08:06
14th may pycon india 2014 irc meetup
[Wed May 14 2014]
*** You have joined channel #pyconindia [19:25]
*** Users on #pyconindia: kracekumar sayan gits1225 n3oo3n_ kirang89_ kaakku
chandankumar techglider_ anuragkr rx100 satyag haseeb_ theskumar Shaan7
Hobbes`
*** #pyconindia modes: +cnt
*** #pyconindia was created on 2012-06-07 13:33:21
*** rx100 (~rradhakri@64.138.135.2) has quit: Read error: Connection reset by
peer [19:27]
@kracekumar
kracekumar / super_py2.py
Created May 18, 2014 17:47
python super in constructors
# IPython interpreter
# Super as a constructor
In [52]: class A(object):
def __init__(self, *args, **kwargs):
self.a_name = kwargs.get('a_name')
super(A, self).__init__(*args, **kwargs)
....:
In [53]: class B(object):
package main
import (
"fmt"
"net/http"
"sync"
"time"
)
func basics() {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kracekumar
kracekumar / pytest-sugar_output
Created September 18, 2014 13:27
pytest sugar output on emacs shell.
Welcome to the Emacs shell
tests $ cd ..
intercom_integration $ cd ..
sample_proj $ workon sample
(sample) sample_proj $ ./test intercom_integration/tests/test_intercom_entity.py
Test session starts (platform: darwin, Python 2.7.5, pytest 2.6.1, pytest-sugar 0.3.4)
plugins: django, sugar
\r \x1b[1;30mintercom_integration/tests/\x1b[0mtest_intercom_entity.py \x1b[92m\u2713\x1b[0m 100% \x1b[92m\x1b[100m\u2589\u2589\u2589\u2589\u2589\u2589\u2589\u2589\u2589\u2589\u2589\x1b[0m\x1b[1;30m\x1b[100m\x1b[0m