Skip to content

Instantly share code, notes, and snippets.

CODE:
-----
#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus-glib.h>
/*
* Test program requesting shutdown to dbus
*/
@nbyouri
nbyouri / brightness.c
Last active November 21, 2022 04:07
Get/Set screen brightness value on NetBSD
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/sysctl.h>
#include <inttypes.h>
bool device_enabled(char *);
char *find_device(void);
int get_brightness(char *);
@nbyouri
nbyouri / counting.jl
Created January 2, 2017 10:56
Small Julia utilities for counting
# C(n,r)
function C(n::Int, r::Int)
return (factorial(n)) / (factorial(r)*factorial(n - r))
end
# P(n,r)
function P(n::Int, r::Int)
return (factorial(n) / factorial(n -r))
end
# Sum of a function in a j .. n range
function ∑(j::Int, n::Int, f::Function)
@nbyouri
nbyouri / pagerank.jl
Last active January 4, 2017 14:23
explication pagerank
# PageRank
# Le graphe en exemple est celui de la Q4 de l'exam 09/2015:
#
# 1 -----→ 4
# ↑ \ ↑
# | `---↘ |
# 2 -----→ 3
#
# Matrice d'adjacence:
A = [ 0 1 1 0;
@nbyouri
nbyouri / levenshtein.jl
Last active August 11, 2017 08:39
Tool to calculate edit-distance (levenshtein number) of two strings
# Compute the edit-distance of two strings, also called the Levenstein number.
function lev(x, y)
# edit-distance array
xl = length(x) + 1
yl = length(y) + 1
m = zeros(Int, xl, yl)
# init first line and column
for i = 1 : yl
m[1, i] = i - 1
@nbyouri
nbyouri / pagerank.m
Last active January 13, 2017 09:00
PageRank in matlab
% Reviewed par Marco Saerens le 13/01/2017
% matrice des degres sortants
n = size(A)
D = diag(sum(A, 2))
% matrice de probabilites de transition
P = D^-1 * A
% ajout d'un lien faible entre tous les liens
alpha = 0.85
% vecteur de 1 de taille n
package Calcu;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Random;
@nbyouri
nbyouri / matmul.dfy
Created May 27, 2017 08:48
squared matrix multiplication in dafny
method matmul(a: array2<int>, b: array2<int>) returns (c : array2<int>)
requires a != null
requires a.Length0 > 0 && a.Length1 > 0
requires a.Length0 == a.Length1 // que pour matrices carrées
requires b != null
requires b.Length0 > 0 && b.Length1 > 0
requires b.Length0 == b.Length1 // que pour matrices carrées
requires a.Length0 == b.Length0
requires a.Length1 == b.Length1
ensures fresh(c)
@nbyouri
nbyouri / powermethod.jl
Last active August 23, 2017 20:20
Power Method for PageRank
#############################################
# PageRank algorithm using the power method #
# youri mouton 18/08/2017 #
#############################################
# Adjacency matrix
A = [ 0 2 0;
0 0 2;
1 1 0];
@nbyouri
nbyouri / huffman.java
Created August 19, 2017 09:16
huffman code
package Révision;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;