Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / settings.xml
Created August 8, 2012 02:42
Maven repository setting
<?xml version="1.0"?>
<settings>
<mirrors>
<mirror>
<id>nexus</id>
<url>http://172.25.21.93:8081/nexus/content/groups/public</url>
<mirrorOf>*</mirrorOf>
</mirror>
<mirror>
<id>Midas-snapshot</id>
@stingh711
stingh711 / mount_ebs.sh
Created July 24, 2012 08:02
How to mount another EBS as /var on EC2 (ubuntu)
#!/bin/bash
#attach the EBS to /dev/sdf before running it
#format EBS
mkfs -t ext4 /dev/xvdf
#copy original /var to /dev/xvdf
mkdir /mnt/new
mount /dev/xvdf /mnt/new
cd /var
@stingh711
stingh711 / OnlyFullGc.java
Created July 17, 2012 07:35
Try to make JVM only do full GC
class OnlyFullGc {
private static final int _1M = 1024 * 1024;
//java -verbose:gc -XX:+PrintGCDetails -XX:PretenureSizeThreshold=3145728 -Xms20M -Xmx20M -Xmn10M OnlyFullGc
//1
//2
//[GC [Tenured: 9216K->4237K(10240K), 0.0110910 secs] 9543K->4237K(19456K), [Perm : 91K->91K(12288K)], 0.0113940 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
//3
//Heap
@stingh711
stingh711 / MaxTenuringThreshold.java
Created July 17, 2012 06:20
Test MaxTenuringThreshold
private static final int _1M = 1024 * 1024;
/**
* Test with -verbose:gc -XX:+PrintGCDetails -Xms20M -Xmx20M -Xmn10M -XX:MaxTenuringThreshold=1
*/
public static void testMaxTenuringThreshold() {
byte[] a1, a2, a3;
a1 = new byte[_1M / 4];
System.out.println(1);
@stingh711
stingh711 / MinorGc.java
Created July 17, 2012 04:51
Test minor GC
private static final int _1M = 1024 * 1024;
/**
* Test with -verbose:gc -XX:+PrintGCDetails -Xms20M -Xmx20M -Xmn10M
*/
public void testMinorGc() {
byte[] a1, a2, a3, a4;
a1 = new byte[_1MG / 2];
System.out.println(1);
a2 = new byte[3 * _1MG];