Skip to content

Instantly share code, notes, and snippets.

View aspyct's full-sized avatar

Antoine d'Otreppe aspyct

View GitHub Profile
c = compile("print('hello')", "noFile", "exec")
f = FunctionType(c, globals())
f()
@aspyct
aspyct / cdscript.sh
Created February 17, 2014 09:10
Go to script's directory
cd `dirname $BASH_SOURCE`
@aspyct
aspyct / rvmsudo.sh
Last active August 29, 2015 13:56
rvmsudo
rvmsudo rvm 1.9.3 do rake install prefix=/usr/local
@aspyct
aspyct / vimrc.vim
Last active August 29, 2015 13:56
My vimrc
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
syntax on
set hidden
set backspace=indent,eol,start
set nu
@aspyct
aspyct / upstart.sh
Created February 3, 2014 12:54
Upstart script
description "My service"
author "Antoine d'Otreppe <a.dotreppe@aspyct.org>"
start on runlevel [35]
stop on runlevel [0126]
exec /path/to/script.sh
respawn
@aspyct
aspyct / sayhello.py
Created January 24, 2014 09:41
Funny python method swap
def sayHello():
print("hello")
def sayBye():
sayBye()
sayHello, sayBye = sayBye, sayHello
@aspyct
aspyct / AndroidManifest.xml
Created May 4, 2013 10:02
Android: switch wifi on/off
<!-- Add these permissions to your android manifest -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
@aspyct
aspyct / signal.c
Last active February 19, 2024 11:24
Unix signal handling example in C, SIGINT, SIGALRM, SIGHUP...
/**
* More info?
* a.dotreppe@aspyct.org
* http://aspyct.org
*
* Hope it helps :)
*/
#include <stdio.h>
#include <stdlib.h>
@aspyct
aspyct / sort.rb
Last active October 29, 2023 03:08
Ruby implementation of quicksort, mergesort and binary search
# Sample implementation of quicksort and mergesort in ruby
# Both algorithm sort in O(n * lg(n)) time
# Quicksort works inplace, where mergesort works in a new array
def quicksort(array, from=0, to=nil)
if to == nil
# Sort the whole array, by default
to = array.count - 1
end
@aspyct
aspyct / heap.rb
Created August 22, 2012 19:42
Binomial heap (priority queue) implementation in ruby
class Heap
def initialize
# @elements is an array representing the tree
# for each i:
# parent => @elements[i / 2]
# left => @elements[i * 2]
# right => @elements[i * 2 + 1]
@elements = []
end