Skip to content

Instantly share code, notes, and snippets.

@moniyax
moniyax / coords_at_dist.rb
Last active July 27, 2017 19:15
Coordinates of a point on surface of earth at a distance and bearing from given point
# http://www.movable-type.co.uk/scripts/latlong.html
# Destination point given distance and bearing from start point
# Radius of earth
R=6371
# Return the lat2 & lon2 of a point at distance d and
# bearing brng from an initial point wt coords lat1 & lon1
def coords_at_dist lat1, lon1, d, brng
# lat1 => latitude at initial point
#lang racket
(define (Pt x y)
(let ([self 0])
(begin
(define (obj method)
(case method
[("getX") (lambda () x)]
[("getY") (lambda () y)]
[("moveX") (lambda (newx) (Pt (+ newx ((self "getX"))) y))]))
#lang racket
(define (isort cs)
(define (insert x xs)
(cond [(empty? xs) (list x)]
[else (if (< x (first xs))
(cons x xs)
(cons (first xs) (insert x (rest xs))))]))
(cond [(empty? cs) cs]
[else (insert (first cs) (isort (rest cs)))]))
@moniyax
moniyax / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@moniyax
moniyax / Car.java
Last active August 4, 2018 16:25
Object things
// A class is used to mint new objects. The class here is used to create new car objects
// in the program. You may think of it as a car factory.
// Classes specify methods and attributes.
// Methods define operations that can be performed on (or by) an object: a car in this case.
// The methods defined in this Car class are "move" and "turn". See the comments written for
// each method for info on their functions.
// Attributes indicate well... attributes of objects. They help ho"ld the state of the object
// at any given instance. The attributes for the car are "location", "brand", "model", and "direction".
// Silly silly old Car
@moniyax
moniyax / freq.awk
Last active August 29, 2015 14:00
Computing frequencies of categories in tab-delimited dataset
awk -F '\t' -v rec=5 '{a[$rec]+=1; sum+=1} END{for(k in a) print k, ":", a[k] "(freq),", a[k]/sum "(prop)"; print "sum:", sum}' file.txt
@moniyax
moniyax / findsp.py
Created January 11, 2014 20:59
Finding site-packages
from distutils.sysconfig import get_python_lib
print(get_python_lib())
@moniyax
moniyax / factorial.scm
Created September 26, 2013 15:28
Factorial in Scheme
(define (fact n)
(cond ((= n 0) 1)
(else (* n (fact (- n 1))))))
(fact 5)
@moniyax
moniyax / lilRock.scala
Last active December 22, 2015 19:59
Little scala assertion lib.
import scala.language.implicitConversions
import scala.language.reflectiveCalls
// implicit def lilRock(foo : Int) = new { def mustEqual(actual : Int) : Boolean = actual == foo }
class Baz(actual: Int) {
def mustEqual(expected : Int) : Boolean = actual == expected
def mustBeGreaterThan(expected : Int) : Boolean = actual > expected
}
@moniyax
moniyax / railspgdb.rb
Last active December 21, 2015 15:49
Script for setting up postgres and configs in a new rails apps.
#!/usr/bin/env ruby
error_message = "Must be run from the root directory of a rails app."
abort(error_message) unless File.exist?("config/database.yml")
app_name = Dir.pwd.split("/")[-1]
dev_db = app_name + "_dev"
test_db = app_name + "_test"
if ARGV[0] == '--delete'
`dropdb #{dev_db} && dropdb #{test_db}`