Skip to content

Instantly share code, notes, and snippets.

View mrklein's full-sized avatar

Alexey Matveichev mrklein

View GitHub Profile
@mrklein
mrklein / gist:07249c2e80c27f476ca4
Created December 1, 2014 17:31
Part of Bouygues Telecom Bbox web interface
function CheckIPString(Str,inCouldBeEmpty)
{
if (Str == "") return inCouldBeEmpty;
var regExpIP = new RegExp("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$");
if (!regExpIP.test(Str)) return false;
var ipArray = Str.split(".");
for (var i = 0; i < 4; i++) {
if ((Math.floor(ipArray[i]) < 0) || (Math.floor(ipArray[i]) > 247)) return false;
}
@mrklein
mrklein / atkin.c
Last active August 29, 2015 14:07
Sieve of Atkin in C
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <math.h>
#define CLOCKTYPE CLOCK_MONOTONIC
uint64_t* sieve_of_atkin_f(uint64_t n);
@mrklein
mrklein / Makefile
Created October 6, 2014 15:23
Arithmetics
leading_zero_strip = $(shell echo $$(echo $(1) | sed 's/^0*//'))
__plus = $(shell echo $$(($(1) + $(2))))
plus = $(call __plus,$(call leading_zero_strip,$(1)),$(call leading_zero_strip,$(2)))
__minus = $(shell echo $$(($(1) - $(2))))
minus = $(call __minus,$(call leading_zero_strip,$(1)),$(call leading_zero_strip,$(2)))
__mult = $(shell echo $$(($(1) * $(2))))
mult = $(call __mult,$(call leading_zero_strip,$(1)),$(call leading_zero_strip,$(2)))
su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm'
Traceback (most recent call last):
File "./plot.py", line 116, in <module>
plot_planes(s)
File "./plot.py", line 75, in plot_planes
P.tricontour(x, y, fl, [0.5], colors='black')
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 3090, in tricontour
ret = ax.tricontour(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 8922, in tricontour
return mtri.tricontour(self, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/tri/tricontour.py", line 280, in tricontour
data = N.loadtxt(filename)
x = 100*data[:, xidx]
y = 100*data[:, yidx]
fl = data[:, flidx]
asp = 4.5/(xlim[1] - xlim[0])
P.figure(figsize=(8, 8*asp))
P.clf()
P.tricontour(x, y, fl, [0.5], colors='black')
from scipy.spatial import Delaunay
from matplotlib.tri import Triangulation
data = N.loadtxt(filename)
x = 100*data[:, xidx]
y = 100*data[:, yidx]
pts = N.column_stack((x, y))
tri = Delaunay(pts)
mtri = Triangulation(x, y, tri.simplices.copy())
alexey at daphne in tests$ clang++ gmp_test.cxx -lgmp -lgmpxx -std=c++11 -O3
alexey at daphne in tests$ ./a.out
2652733
Execution time: 8394.96 ms
alexey at daphne in tests$
#include <iostream>
#include <ctime>
#include <gmpxx.h>
typedef mpz_class Integer;
Integer N[] = {1, 12, 123, 1234, 12345, 123456};
Integer sum_digits(Integer n);
Integer factorial(Integer n);
@mrklein
mrklein / stream-function-mpl.py
Last active December 31, 2015 16:09
streamFunction.patch
diff -ru streamFunction/Make/files streamFunctionV/Make/files
--- streamFunction/Make/files 2013-06-11 11:33:58.000000000 +0200
+++ streamFunctionV/Make/files 2013-12-17 15:15:36.255538814 +0100
@@ -1,3 +1,3 @@
streamFunction.C
-EXE = $(FOAM_APPBIN)/streamFunction
+EXE = $(FOAM_USER_APPBIN)/streamFunctionV
diff -ru streamFunction/streamFunction.C streamFunctionV/streamFunction.C
--- streamFunction/streamFunction.C 2013-06-11 11:33:58.000000000 +0200