Skip to content

Instantly share code, notes, and snippets.

# You will be prompted for sudo (password) if you haven't used it recently.
# First of all
sudo apt-get update
# Virtualbox guest additions
sudo apt-get install build-essential linux-headers-`uname -r` dkms
# Apt-fast
sudo apt-get install software-properties-common
@0xKD
0xKD / chunks_slice.py
Created November 13, 2014 07:10
Chunk and slice operations on lists in Python
from itertools import izip_longest
from string import lowercase
def chunk(s, size):
'''
Separates sequence into chunks of given size.
>>> chunk('helloworld', 3)
['hel', 'low', 'orl', 'd']
@0xKD
0xKD / mergesort.js
Created November 22, 2014 17:16
Merge sort (variant) in JavaScript
(function(){
'use strict';
var randomArray = function(size) {
var arr = [];
for(var i=0;i<size;i++) {
arr.push(Math.round(Math.random() * size * 10));
}
return arr;
};
@0xKD
0xKD / plots.py
Created November 23, 2014 03:35
Simple Complexity chart (IPython notebook & matplotlib)
import math
import matplotlib.pyplot as plt
%matplotlib inline
a = range(1,100)
b = map(lambda x:x*math.log(x,2), a)
c = map(lambda x:x*x, a)
d = map(lambda x:2**x, a)
p = plt.figure()
from __future__ import print_function
p, q = 0x6f095e5b39, 0x7377497f7b
def g(num):
return ((p if num < 5 else q) % (16 ** (10 - (num % 5) * 2 or 2))) // \
(16 ** ((10 - (num % 5) * 2 or 2) - 2))
@0xKD
0xKD / admin.py
Created May 11, 2015 12:13
Django code snippet that will treat a save button click (when URL has ?_popup=1) as 'Save and continue'. This is useful when you need to save the object before allowing some changes to be made on it
class MyAdmin(admin.ModelAdmin):
def response_add(self, request, obj, post_url_continue=None):
# If object is added in popup, treat as continue
if '_popup' in request.POST:
opts = obj._meta
pk_value = obj._get_pk_val()
preserved_filters = self.get_preserved_filters(request)
msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)}
msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict
self.message_user(request, msg, messages.SUCCESS)
@0xKD
0xKD / preferences.json
Last active August 31, 2015 01:06
ST3 : Preferences
{
"bold_folder_labels": true,
"color_scheme": "Packages/User/SublimeLinter/base16-ocean.dark (SL).tmTheme",
"dictionary": "Packages/Language - English/en_GB.dic",
"draw_centered": true,
"fade_fold_buttons": false,
"font_face": "Monaco",
"font_size": 16,
"highlight_line": true,
"ignored_packages":
@0xKD
0xKD / .vimrc
Last active May 18, 2016 16:18
set nocompatible " be iMproved, required
filetype off " required!
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle
" required!
Plugin 'gmarik/Vundle.vim'
" git helper
@0xKD
0xKD / tmux.conf
Created September 4, 2015 07:06
Tmux server config
unbind C-b
set -g prefix C-a
setw -g monitor-activity on
set -g visual-activity on
@0xKD
0xKD / pexp.py
Created September 6, 2015 10:17
Process CSV export from 'My Expenses' app, save in sqlite, and make pie chart / time series using matplotlib.
"""
Columns for reference:
cols = ('_split', 'Date', '_payee', 'Income', 'Expense', 'Category',
'Subcategory', 'Notes', '_method', '_status', '_refnum', '_unknown')
"""
import csv
from datetime import datetime
import matplotlib.pyplot as plt
import os