Skip to content

Instantly share code, notes, and snippets.

import math
def get_distance_in_meters(lat1, lon1, lat2, lon2):
earth_radius = 6371007.2 # meters
lat1, lon1, lat2, lon2 = map(math.radians, (lat1, lon1, lat2, lon2))
dlon = lon2 - lon1
dlat = lat2 - lat1
a = math.sin(dlat / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2) ** 2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
import re
def roman_to_int(r):
r = r.strip().lower()
r_original = r
r = r.rstrip('i')
right_i_num = len(r_original) - len(r)
def parse_group(g):
import numpy as np
from shapely.geometry import Polygon, Point
from PIL import Image
import os
import sys
import csv
import pickle
import json
import random
import string
@precious
precious / Bidders.js
Last active September 23, 2017 13:14
'use strict';
class Bidder {
constructor(quantity, cash) {
/*
quantity: integer even number of lots
each time exactly 2 lots are sold
so there will be exactly quantity/2 iterations
it's guaranteed that this number is positive
@precious
precious / minifier.py
Last active December 24, 2016 20:06
bash scripts minifier
#!/usr/bin/python
import sys
class BashFileIterator:
def __init__(self, src):
self.src = src
self.reset()
def reset(self):
delim(){
if [ -n "`/home/precious/programming/c/git_branch/git-br`" ]; then
echo '|'
fi
}
export PS1='\[\e[0;36m\]$?\[\e[0m\]|\[\e[0;31m\]`/home/precious/programming/c/git_branch/git-br`\[\e[0m\]$(delim)\[\e[0;35m\]\u\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '
children(Parent,L) :- findall(Next,parent(Parent,Next),L).
ancestors(Child,L) :- findall(Next,parent(Next,Child),L).
repr_internal(Elem,L,R) :- (L == [] -> ancestors(Elem,R); children(Elem,R)).
repr_retval(Elem,R) :- children(Elem,L), repr_internal(Elem,L,R).
repr(Elem):- repr_retval(Elem,R), write(R).
read_line_pls(L) :- read_line(X),string_to_atom(X,L).
main :-
#!/usr/bin/python
# -*- coding: utf-8 -*-
from math import *
import sys
# generator for values [a,b] with step 'step'
def frange(a,b,step):
while a <= b:
yield a
a += step
@precious
precious / khizha acl2 tasks
Created October 25, 2012 00:03
funcs.lisp
(defun natural (a)
(and (integerp a) (> a 0))
)
(defun fib (x)
(if (and (integerp x) (>= x 0))
(if (< x 2)
1
(+ (fib (- x 1)) (fib (- x 2)))
)
@precious
precious / test.html
Created May 22, 2012 00:29
function to read file inside JS
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function handleFileSelect(input,callback) {
// used links:
// http://www.w3.org/TR/file-upload/