Skip to content

Instantly share code, notes, and snippets.

View mrklein's full-sized avatar

Alexey Matveichev mrklein

View GitHub Profile
@mrklein
mrklein / fcgen.py
Created July 13, 2012 02:37
Creating flashcards from plain text files for FlipCards app
#!/usr/bin/env python
import sys
import argparse
import os.path
from json import dump
from string import join
import time
import tempfile
import zipfile
@mrklein
mrklein / euler87,py
Created September 8, 2012 14:30
Euler 87
#!/usr/bin/env python
from libeuler import primes
if __name__ == '__main__':
p = primes(7100)
res = set()
for s in p:
for c in p:
for q in p:
@mrklein
mrklein / euler87.py
Created September 8, 2012 14:30
Euler 87
#!/usr/bin/env python
from libeuler import primes
if __name__ == '__main__':
p = primes(7100)
res = set()
for s in p:
for c in p:
for q in p:
@mrklein
mrklein / factorial.lisp
Created September 16, 2012 13:36
factorial
(defun factorial (n)
(defun i_factorial (n acc)
(if (= 0 n)
acc
(i_factorial (- n 1) (* acc n))))
(i_factorial n 1))
(defun print-factorial (n)
(format T "~D~%" (factorial n)))
@mrklein
mrklein / factorial.rkt
Created September 16, 2012 13:37
factorial in Racket
#lang racket
(define (factorial n)
(define (i_factorial n acc)
(if (= 0 n)
acc
(i_factorial (- n 1) (* n acc))))
(i_factorial n 1))
(map (lambda (n)
@mrklein
mrklein / euler125.py
Created September 26, 2012 23:19
Euler #125
#!/usr/bin/env python
from math import sqrt, floor
N = 100000000
def is_palindrome(n):
return str(n) == str(n)[::-1]
def sum_list(n):
@mrklein
mrklein / test.lisp
Created September 26, 2012 23:23
Summing digits of factorials
(defun factorial (n)
(defun i_factorial (k acc)
(if (= 0 k)
acc
(i_factorial (- k 1) (* k acc))))
(i_factorial n 1))
(defun digits (n)
(defun i_digits (k acc)
(if (= 0 k)
@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"
)
@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());
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