Skip to content

Instantly share code, notes, and snippets.

# Heapsort
class Heap:
def __init__(self, lst):
self.list = [len(lst)] + lst
k = self.poslastparent()
while k >= self.posroot():
self.sink(k)
k -= 1
def insert(self, val):
#include <glob.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#define NUM_WORKERS 3
@vierbergenlars
vierbergenlars / vid2mp3.php
Last active December 18, 2015 00:39
Convert video files to mp3 audio. Processes some videos simultaneous for better use of multi-core systems. Requires avconv.
#!/usr/bin/env php
<?php
// ##### START config
$files = glob('*.{mp4,flv}', GLOB_BRACE); // File types to convert to mp3 (video only)
$worker_num = 3; // number of cores +1
// ##### END config
$len = count($files);
$worker_pids = array();
function pr($s) {
@vierbergenlars
vierbergenlars / .conkyrc
Last active December 18, 2015 00:08
Installation instructions: Install fonts (move to /usr/share/fonts/); Move files as indicated
# About this gist: http://vierbergenlars.wordpress.com/2013/06/07/tweaking-ubuntu-gnome-with-conky/
# Conky settings #
background no
update_interval 1
cpu_avg_samples 2
net_avg_samples 2
if_up_strictness address
def count(lst, elem):
if len(lst) == 1:
return lst[0] == elem
else:
return count(lst[1:], elem) + (lst[0] == elem)
@vierbergenlars
vierbergenlars / install.sh
Last active December 16, 2015 18:59
Kotnet login script. Just run sudo ./install.sh
apt-get install -y perl libwww-mechanize-perl
mv kotnet_login.pl /etc/NetworkManager/dispatcher.d/02kotnet
ln -s /etc/NetworkManager/dispatcher.d/02kotnet /etc/init.d/kotnet
update-rc.d kotnet defaults
#deb cdrom:[Ubuntu-GNOME 13.04 _Raring Ringtail_ - Release amd64 (20130424)]/ raring main multiverse restricted universe
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://be.archive.ubuntu.com/ubuntu/ raring main restricted
deb-src http://be.archive.ubuntu.com/ubuntu/ raring main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://be.archive.ubuntu.com/ubuntu/ raring-updates main restricted
@vierbergenlars
vierbergenlars / 0-litus-installer.md
Last active March 6, 2021 14:19
Litus installation
@vierbergenlars
vierbergenlars / gist:5191906
Last active January 3, 2017 13:14
Recursively fix the PHP coding style on all commits in a repository
# Run these commands and the repo will be back in sync
# Note: tags are lost, because the commits are rewritten
sudo curl http://cs.sensiolabs.org/get/php-cs-fixer.phar -o /usr/local/bin/php-cs-fixer
sudo chmod a+x /usr/local/bin/php-cs-fixer
git filter-branch --tree-filter "php-cs-fixer fix .>/dev/null" --all
@vierbergenlars
vierbergenlars / bogosort.py
Created March 12, 2013 11:18
Fastest sorting algorithm ever! Introducing BogoSort
#!/usr/bin/env python
"""
http://acm.zhihua-lai.com
BogoSort.py
Bogo Sorting Algorithm
30/May/2012
https://raw.github.com/DoctorLai/Algorithms/master/Sorting/BogoSort.py
"""
from random import *