Skip to content

Instantly share code, notes, and snippets.

View aspyct's full-sized avatar

Antoine d'Otreppe aspyct

View GitHub Profile
@aspyct
aspyct / check_server.sh
Created June 25, 2012 14:31
Perl & Bash scripts to warn you if your website is failing
#!/bin/bash
# Actual recipient and sender are defined in another file
script_dir=`dirname $0`;
script_name=`basename $0`;
config_file="$script_dir/config-$script_name";
if [ -f $config_file ]; then
source $config_file;
else
@aspyct
aspyct / NodeJs example .js
Created June 26, 2012 12:45
A short dependency container for javascript / node applications
> var sb = new ServiceBox();
> sb.msg = "Hello World";
> var handler = sb.wrap(function (prefix) {
... console.log(prefix);
... console.log(this.msg);
... });
> handler("this is the prefix");
this is the prefix
Hello World
@aspyct
aspyct / common.h
Created July 15, 2012 22:00
Unix semaphore with the C programming language, tested under Debian
#ifndef _COMMON_H_
#define _COMMON_H_
#define SEM_KEY_FILE ("sem.key")
#endif /* _COMMON_H_ */
@aspyct
aspyct / RBTree.java
Created July 17, 2012 13:22
Left Leaning Red/Black Tree implemented in Java
package org.aspyct.going;
import java.util.Iterator;
import java.util.Stack;
/**
* This is an implementation of the Left Leaning Red/Black Tree as
* described in the course from the University of Princeton.
*
* This code contains a lot of assertions (assert ;).
@aspyct
aspyct / display-double.cpp
Created July 28, 2012 21:31
A small program to display binary representation of double numbers
/*
* File: display-double.cpp
* Author: aspyct
*
* Can be compiled to a binaly that displays the binary value of double numbers.
* Usage : ./a.out <number1> ... <number n>
* Example: ./a.out 1.0 2.5
*
* Created on July 28, 2012, 11:03 PM
*/
@aspyct
aspyct / workaround.php
Created August 22, 2012 16:10
The most undebuggable PHP snippet ever
<?php
define("true ", false);
function doIt() {
define(" false", true);
define("maybe", rand() & 1);
}
function  ($stupid="clever") {
if (assert_value($stupid)) {
@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
@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 / 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 / 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"/>