Skip to content

Instantly share code, notes, and snippets.

View mrklein's full-sized avatar

Alexey Matveichev mrklein

View GitHub Profile
@mrklein
mrklein / gmp_test.c
Created May 5, 2013 14:52
Calculation of factorial and sum of number digits with GMP. Timing implemented for OS X.
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <mach/mach_time.h>
#include <gmp.h>
void factorial(mpz_t n, mpz_t res)
{
mpz_t unit, zero, cnt;
mpz_init_set_ui (unit, 1);
@mrklein
mrklein / factorial.scm
Last active December 17, 2015 00:29
Two variant of factorial implementation with Bigloo Scheme. Bigloo specifics are in timing of calculations. Tested under Bigloo 4.0a.
(module fact)
(define *num-list* '(1 12 123 1234 12345 123456))
(define (factorial n)
(define (iter k acc)
(if (= k 1)
acc
(iter (- k 1) (* k acc))))
(iter n 1))
@mrklein
mrklein / gist:5117819
Created March 8, 2013 16:41
Reconstructing case on the cluster
#PBS -l nodes=1
cd $PBS_O_WORKDIR
reconstructPar -case $PBS_O_WORKDIR > $PBS_O_WORKDIR/log.reconstructPar
const fvPatchList& patches = mesh.boundary();
forAll(patches, patchi)
{
const fvPatch& curPatch = patches[patchi];
if (isType<wallFvPatch>(curPatch))
{
forAll(curPatch, facei)
{
label faceCelli = curPatch.faceCells()[facei];
;; for OpenFOAM
(c-add-style "OpenFOAM_HGW"
'(
(c-basic-offset . 4)
(c-tab-always-indent . t)
(indent-tabs-mode . nil)
(c-comment-only-line-offset . (0 . 0))
(c-indent-comments-syntactically-p . t)
(c-block-comments-indent-p nil)
(c-cleanup-list .
" OpenFOAM/FreeFOAM
autocmd BufRead *.[CH] set expandtab shiftwidth=4 filetype=cpp
autocmd BufRead *.[CH] set cindent cinoptions=+s-2,(s,U1,is,g0,Ws,l1,t0 cinkeys=0{,0},0),:,!^F,o,O,e
#!/bin/bash
CHAIN=SELFCONTROL
IPTABLES=/sbin/iptables
IP_PATTERN='/^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$/p'
usage() {
echo "Usage: $0 <IP address or hostname>"
exit 1
}
def point_on_arc(radius, start_x, start_y, end_x, end_y):
"""
Returns set of possible points on arc given by start and end points and
circle radius.
Return value is dictionary with keys 'center' and 'points'.
Center is associated with list of tuples with possible center coordinates.
Points is associated with list of tuples with possible points on the arc.
"""
X = start_x - end_x
Y = start_y - end_y
@mrklein
mrklein / apps_script_extract_inline_images_from_gmail.js
Created October 8, 2012 12:40 — forked from anonymous/apps_script_extract_inline_images_from_gmail.js
Google Apps Script quick hack to extract inline images from Gmail
function fetchInlineImage() {
var results = GmailApp.search("Subject: Inline Image Test");
for(var i in results) {
var thread = results[i];
messages = thread.getMessages();
for(var j in messages) {
var msg = messages[j];
var pattern = /<img.*src="([^"]*)"[^>]*>/;
var matches = pattern.exec(msg.getBody());
@mrklein
mrklein / test.go
Created September 26, 2012 23:24
Summing digits of factorials in Go
package main
import (
"fmt"
"math/big"
"strings"
"strconv"
"time"
)