Skip to content

Instantly share code, notes, and snippets.

View mlliarm's full-sized avatar

Michail Liarmakopoulos mlliarm

View GitHub Profile
@ademar
ademar / gist:1016874
Created June 9, 2011 14:49
Combinators for logic programming
// Based on the article 'Combinators for logic programming' by Michael Spivey and Silvija Seres.
let rec inf_seq n = seq { yield n; yield! inf_seq (n+1) }
let rec lzw f l1 l2 =
LazyList.delayed ( fun () ->
match l1,l2 with
|LazyList.Nil, _ -> l2
|_, LazyList.Nil -> l1
|LazyList.Cons(p1,tail1),LazyList.Cons(p2,tail2)
@endolith
endolith / readme.md
Last active May 22, 2024 07:13
How to stream a webcam to a web browser in Ubuntu

Grr this took hours to figure out. I was trying to install MJPG-streamer and running VLC command lines and all this crap but nothing worked.

First install motion:

~> sudo apt-get install motion

Then create a config file:

~> mkdir ~/.motion

~> nano ~/.motion/motion.conf

@melpomene
melpomene / lagrange.py
Created April 24, 2012 19:27
Lagrange interpolation in python
import numpy as np
import matplotlib.pyplot as plt
import sys
def main():
if len(sys.argv) == 1 or "-h" in sys.argv or "--help" in sys.argv:
print "python lagrange.py <x1.y1> .. <x_k.y_k>"
print "Example:"
print "python lagrange.py 0.1 2.4 4.5 3.2"
@stevenworthington
stevenworthington / ipak.R
Created July 25, 2012 19:44
Install and load multiple R packages at once
# ipak function: install and load multiple R packages.
# check to see if packages are installed. Install them if they are not, then load them into the R session.
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
@yihui
yihui / README.md
Last active June 30, 2021 18:01
Preview all syntax highlighting themes in knitr (HTML and LaTeX)
anonymous
anonymous / gist:f72e5c4a432492abce59
Created October 30, 2014 18:41
Arthur Whitney's interpreter, decompressed
typedef char C;
typedef long I;
typedef struct a {
I t,r,d[3],p[2];
}* A;
#define P printf
@psayre23
psayre23 / gist:c30a821239f4818b0709
Last active June 8, 2024 19:07
Runtime Complexity of Java Collections
Below are the Big O performance of common functions of different Java Collections.
List | Add | Remove | Get | Contains | Next | Data Structure
---------------------|------|--------|------|----------|------|---------------
ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array
LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List
CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array
@pezy
pezy / Lucy_Hedgehog
Last active April 27, 2018 04:30
10亿内质数和
Here is a solution that is more efficient than the sieve of Eratosthenes. It is derived from similar algorithms for counting primes. The advantage is that there is no need to find all the primes to find their sum.
The main idea is as follows: Let S(v,m) be the sum of integers in the range 2..v that remain after sieving with all primes smaller or equal than m. That is S(v,m) is the sum of integers up to v that are either prime or the product of primes larger than m.
S(v, p) is equal to S(v, p-1) if p is not prime or v is smaller than p*p. Otherwise (p prime, p*p<=v) S(v,p) can be computed from S(v,p-1) by finding the sum of integers that are removed while sieving with p. An integer is removed in this step if it is the product of p with another integer that has no divisor smaller than p. This can be expressed as
S(v,p)=S(v,p−1)−p(S(v/p,p−1)−S(p−1,p−1)).
Dynamic programming can be used to implement this. It is sufficient to compute S(v,p) for all positive integers v that are representable as floor(n/k) for
#!/usr/bin/bash
xconfig="/etc/X11/xorg.conf"
if [ -e "$xconfig" ]
then
echo "Nvidia xconfig detected"
echo "Switching to mesa..."
sudo pacman -S lib32-mesa-libgl mesa-libgl
sudo rm $xconfig
else