Skip to content

Instantly share code, notes, and snippets.

@oleg
oleg / gist:852469
Created March 3, 2011 07:27
pascal
padStart list = 0 : list
padEnd list = list ++ [0]
next l = zipWith (+) (padEnd l) (padStart l)
pascal d
| d <= 0 = []
| d == 1 = [1]
| d == 2 = [1, 1]
| otherwise = next $ pascal $ d - 1
@oleg
oleg / RssToPostTestV1.java
Created February 11, 2012 14:36
example of refactoring
package logic;
import org.junit.Test;
import play.test.UnitTest;
public class RssToPostTestV1 extends UnitTest {
public static final String USER_ID = "[email protected]";
public static final String URL =
"http://shpilenok.livejournal.com/data/rss";
package logic;
public class WordWrap {
public static String wrap(String input, int length) {
return null;
}
}
@oleg
oleg / IsolatedTestV1.java
Created February 26, 2012 11:20
Isolation
package logic;
import org.junit.Assert;
import org.junit.Test;
import play.Play;
import java.util.Properties;
public class IsolatedTestV1 extends Assert {
static {
@oleg
oleg / BddTest.java
Created February 27, 2012 18:46
Mockito BDD style
package logic;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.matchers.JUnitMatchers.hasItem;
package logic;
import org.junit.Assert;
import org.junit.Test;
import org.w3c.dom.Document;
import play.libs.XML;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
@oleg
oleg / Main.java
Created March 14, 2013 08:29
Simple download automatisation
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Main {
public static void main(String[] args) throws IOException {
@Test
public void comparing_date_and_timestamp() throws Exception {
long millis = 1383057201173L;
java.sql.Timestamp timestamp = new java.sql.Timestamp(millis);
java.util.Date date = new java.util.Date(millis);
//wtf
assertTrue(date.equals(timestamp));
assertTrue(date.after(timestamp));
@oleg
oleg / doc2epub.sh
Last active August 29, 2015 13:55
Convert doc to epub with calligra
for f in ls *.doc ; do calligraconverter "$f" $(echo "out/${f%.doc}" | sed 's/[ ,.-]//g').epub; done;
find . -name "*.epub" -exec unzip {} -d {}.dir \;
zip -X title.epub mimetype
zip -rg title.epub META-INF
zip -rg title.epub OEBPS
@oleg
oleg / BigDecimalZeroEequalsTest.java
Last active August 29, 2015 13:56
BigDecimal zero equals showcase
@Test
public void test() throws Exception {
final BigDecimal Z0 = new BigDecimal("0");
final BigDecimal Z1 = new BigDecimal("0.0");
final BigDecimal Z2 = new BigDecimal("0.00");
final BigDecimal Z5 = ZERO.setScale(5);
assertFalse(Z0.equals(Z1));
assertFalse(Z1.equals(Z2));