Skip to content

Instantly share code, notes, and snippets.

View tuxcanfly's full-sized avatar
🏠
Working from home

Javed Khan tuxcanfly

🏠
Working from home
View GitHub Profile
@tuxcanfly
tuxcanfly / gitup.sh
Created November 28, 2016 15:44
gitup - update multiple repos while taking care of dirty indexes in different branches
#!/bin/bash
for dir
do
pushd $dir
STASHED=false
BRANCH=false
if [[ -n $(git status --porcelain) ]]
then
git stash
// morse.go
// usage:
// go run morse.go "SOS" > sos.au
package main
import (
"encoding/binary"
"fmt"
"io"
# -*- coding: utf-8 -*-
print '₂₀₁₄'
#!/usr/bin/env python
import os
import logging
from threading import Thread
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
# vim: ft=sh
unbind C-b
set -g prefix `
bind-key ` send-prefix
bind j select-pane -t :.+
bind k select-pane -t :.-
set -sg escape-time 1
set -g default-terminal "rxvt-unicode"
setw -g mode-mouse on
@tuxcanfly
tuxcanfly / miner.py
Last active December 15, 2015 18:59
from hashlib import sha256
def mine_block(message, target, prev_block=''):
"""
use the message and previous block to generate a new block
"""
nonce = 0
if prev_block:
message = '%s\n%s' % (message, prev_block)
@tuxcanfly
tuxcanfly / django-wtf.py
Created March 26, 2013 09:28
Django forms won't clean a second time.
>>> from django.contrib.auth.forms import UserCreationForm
>>> form = UserCreationForm({'username': 'admin123', 'password1': 's3cr3t', 'password2': 's3cr3t'})
>>> form.is_valid()
True
>>> form.data['username'] = ''
>>> form.is_valid()
True
>>> form._errors = None
>>> form.is_valid()
False
class ImportFieldForm(LazyModelForm):
label = forms.ChoiceField(choices=(), required=False)
header = forms.ChoiceField(choices=(), required=False, error_messages={'valid': 'Please choose a star rating'})
class Meta:
model = ImportField
def __init__(self, *args, **kwargs):
self.labels = kwargs.pop('labels')
self.headers = kwargs.pop('headers')
self.helper = FormHelper()
>pip install kivy
Downloading/unpacking kivy
Running setup.py egg_info for package kivy
[INFO ] Kivy v1.4.1
Found GLES 2.0 headers at /usr/include/GLES2/gl2.h
Installing collected packages: kivy
Running setup.py install for kivy
[INFO ] Kivy v1.4.1
Found GLES 2.0 headers at /usr/include/GLES2/gl2.h
package main
import "fmt"
import "tour/tree"
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
_Walk(t, ch)
close(ch)