Skip to content

Instantly share code, notes, and snippets.

@stingh711
stingh711 / Issue3.scala
Created August 22, 2012 03:09
Project euler problem 3 solution
import java.lang.Math
object Issue3 {
def isPrime(n: Long) = {
if (n <= 1) false
else if (n == 2) true
else if (n % 2 == 0) false
else {
val max = Math.sqrt(n).toInt
!3.to(max, 2).exists(n % _ == 0)
@stingh711
stingh711 / Issue4.scala
Created August 22, 2012 05:51
Project euler problem 4 solution
object Issue4 {
val MIN = 100
val MAX = 999
def isPalindromic(n: Int) = {
val s = n.toString
s == s.reverse
}
def maxPalindromic() = {
@stingh711
stingh711 / Issue5.scala
Created August 22, 2012 05:54
Project euler problem 5 solution
object Issue5 {
def gcd(a: Long, b: Long): Long = {
if (b == 0) a else gcd(b, a % b)
}
def lcm(a: Long, b: Long) = {
a * b / (gcd(a, b))
}
def smallestLcm(l: List[Long]) = {
@stingh711
stingh711 / euler4.clj
Created September 4, 2012 08:32
Project euler issue 4 solution in clojure
(defn reverse-str
[s]
(apply str (reverse s)))
(defn palindromic?
[n]
(let [s (str n)]
(= (reverse-str s) s)))
(apply max (filter palindromic? (for [x (range 100 1000) y (range 100 1000)] (* x y))))
@stingh711
stingh711 / euler5.clj
Created September 4, 2012 08:37
Project euler issue 5 solution in clojure
(defn gcd
[a b]
(if (zero? b)
a
(gcd b (rem a b))))
(reduce (fn [a b] (/ (* a b) (gcd a b))) (range 1 21))
@stingh711
stingh711 / receiver.clj
Created September 21, 2012 09:02
A simple UDP server in clojure
(import '(java.net DatagramSocket DatagramPacket))
(def socket (DatagramSocket. 5200))
(def running (atom true))
(def buffer (make-array Byte/TYPE 1024))
(defn parse [packet]
(println (String. (.getData packet) 0 (.getLength packet))))
(defn start-receiver []
@stingh711
stingh711 / .Xdefaults
Created December 3, 2012 02:30
Urxvt configuration
Rxvt.background:white
Rxvt.foreground:black
Rxvt.colorBD:yellow
Rxvt.colorUL:green
Rxvt.multichar_encoding:gb2312
Rxvt.scrollBar:Fault
Rxvt.scrollBar_right:True
Rxvt.scrollBar_floating: True
Rxvt.scrollstyle: next
Rxvt.saveLines:10000
@stingh711
stingh711 / English.html
Created March 5, 2013 05:46
My English resume
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Resume</h1>
<h2>Basic Information</h2>
@stingh711
stingh711 / index.html
Created May 6, 2013 13:26
bootstrap sample
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<link rel="stylesheet" href="./backup.css" type="text/css" media="screen" title="no title" charset="utf-8"/>
<style type="text/css">
</style>
</head>
<body>
<div class="navbar navbar-static-top navbar-inverse">
(ns pdms.core
(:use korma.core
[korma.db :only (defdb)]))
(def db-spec {:subprotocol "postgresql"
:subname "//localhost/pdms"
:user "huleehom"
:password ""})
(defdb db db-spec)