Skip to content

Instantly share code, notes, and snippets.

@gennad
gennad / BFSDFS.java
Created January 23, 2011 09:14
Breadth-first search and depth-first search Java implementation
Class Main {
public void bfs()
{
// BFS uses Queue data structure
Queue queue = new LinkedList();
queue.add(this.rootNode);
printNode(this.rootNode);
rootNode.visited = true;
while(!queue.isEmpty()) {
Node node = (Node)queue.remove();
@abyx
abyx / RetrierTest.java
Created March 31, 2011 20:51
Simple JUnit rule to make tests retry
public class RetrierTest {
private static int count = 0;
@Rule public RetryRule rule = new RetryRule();
@Test
@Retry
public void failsFirst() throws Exception {
count++;
assertEquals(2, count);
@kdabir
kdabir / html_markup.groovy
Last active September 15, 2020 05:15
Using MarkupBuilder to generate html markup in groovy
// MarkupBuilder is a lot cleaner way of generating valid xml/html markup
// than writing tags as string and forgetting to close one ;)
def writer = new StringWriter() // html is written here by markup builder
def markup = new groovy.xml.MarkupBuilder(writer) // the builder
markup.html{
table {
tr {
td(class:"row", "hello world!")
@henrik
henrik / ocr.markdown
Created March 3, 2012 17:07
OCR on OS X with tesseract

Install ImageMagick for image conversion:

brew install imagemagick

Install tesseract for OCR:

brew install tesseract --all-languages

Or install without --all-languages and install them manually as needed.

@TomTasche
TomTasche / feedback_android.java
Created October 21, 2012 12:22
Use built-in feedback mechanism on Android
// more information here: http://blog.tomtasche.at/2012/10/use-built-in-feedback-mechanism-on.html
try {
int i = 3 / 0;
} catch (Exception e) {
ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = getApplication()
.getPackageName();
report.time = System.currentTimeMillis();
report.type = ApplicationErrorReport.TYPE_CRASH;
@kriegerd
kriegerd / gist:4688748
Last active April 19, 2019 01:42
Multi artifact UploadArchives from a Gradle build file.
artifacts {
archives file: 'A.jar', name: 'A', type: 'jar'
archives file: 'B.jar', name: 'B', type: 'jar'
}
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: "dav:https://myRepo.com/release/") {
@michail-nikolaev
michail-nikolaev / build.gradle
Created March 14, 2013 15:01
Gradle - force transitive dependency version for some group
apply plugin: 'java'
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
//specifying a fixed version for all libraries with 'org.gradle' group
if (details.requested.group == 'org.springframework') {
details.useVersion "$springVersion"
}
}
@KodeSeeker
KodeSeeker / LowestCommonAncestorBinaryTree.java
Created March 14, 2013 22:31
Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree Avoid storing additional nodes in a data structure NOTE: This is not necessarily a binary search tree
/*
Approach similar to approach for Common ancestor for BST. Keep going down on one side(right or left) if both the nodes
are in the same side(right or left), else the current node is the lowest common ancestor*/
public Tree commonAncestor(Node root, Node p, Node q) {
// 1st check if p and q, both belong to the left of the current root node, if yes then recurse on the left side
if (covers(root.left, p) && covers(root.left, q)) // check out the covers subroutine, can be used elsewhere too!
return commonAncestor(root.left, p, q);
// else, check if both p and q are children of right side of the root, if yes, then recurse on the right side
if (covers(root.right, p) && covers(root.right, q))
@mojavelinux
mojavelinux / Gemfile
Last active September 12, 2016 14:24
Guard AsciiDoc and LiveReload minimal setup
source 'https://rubygems.org'
gem 'asciidoctor'
gem 'guard-asciidoc', :github => 'asciidoctor/guard-asciidoc'
gem 'guard-livereload'
gem 'rb-inotify', '~> 0.9.0'
@johanneswuerbach
johanneswuerbach / .travis.yml
Last active May 14, 2024 03:50
Deploy an iOS app to testflight using Travis CI
---
language: objective-c
before_script:
- ./scripts/travis/add-key.sh
after_script:
- ./scripts/travis/remove-key.sh
after_success:
- ./scripts/travis/testflight.sh
env:
global: