Skip to content

Instantly share code, notes, and snippets.

View robinst's full-sized avatar

Robin Stocker robinst

View GitHub Profile
@robinst
robinst / gist:95e9222aac69484483c4
Created June 10, 2015 08:25
commonmark.js test input
a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a_ a
// The information whether head,index,merge iterators are currently
// pointing to file/folder/non-existing is encoded into this variable.
//
// To decode write down ffMask in hexadecimal form. The last digit
// represents the state for the merge iterator, the second last the
// state for the index iterator and the third last represents the state
// for the head iterator. The hexadecimal constant "F" stands for
// "file",
// an "D" stands for "directory" (tree), and a "0" stands for
// non-exisiting
@robinst
robinst / structural-types.scala
Created May 12, 2011 12:51
Duck Typing in Scala
class Duck {
def quack = println("The duck quacks")
def walk = println("The duck walks")
}
class Dog {
def quack = println("The dog quacks (barks)")
def walk = println("The dog walks")
}
@robinst
robinst / jgit-checkout-dir.java
Created August 13, 2012 08:20
JGit checkout of directory
@Test
public void testCheckoutOfDirectoryShouldBeRecursive() throws Exception {
File a = writeTrashFile("dir/a.txt", "A");
File b = writeTrashFile("dir/sub/b.txt", "B");
git.add().addFilepattern("dir").call();
write(a, "modified");
write(b, "modified");
git.checkout().addPath("dir").call();
@robinst
robinst / VarargWithArray.java
Created October 1, 2012 10:45
VarargWithArray dangerous
import java.util.Arrays;
public class VarargWithArray {
public static void main(String[] args) {
int[] ints = {1, 2, 3};
MyList l = new MyList(ints);
ints[0] = 666;
System.out.println(l);
}
@robinst
robinst / MergeBaseForkPoint.java
Created February 12, 2016 04:28
`git merge-base --fork-point` using JGit (not optimal)
public static Optional<RevCommit> findForkPoint(Repository repository, String base, String tip) throws IOException {
try (RevWalk walk = new RevWalk(repository)) {
RevCommit tipCommit = walk.lookupCommit(repository.resolve(tip));
List<ReflogEntry> reflog = repository.getReflogReader(base).getReverseEntries();
if (reflog.isEmpty()) {
return Optional.empty();
}
// The `<=` is deliberate because we want to check both new and old IDs for the oldest entry
for (int i = 0; i <= reflog.size(); i++) {
ObjectId id = i < reflog.size() ? reflog.get(i).getNewId() : reflog.get(i - 1).getOldId();
@robinst
robinst / docker-build.txt
Created December 14, 2016 06:51
docker build output for centos:7
Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM centos:7
---> 980e0e4c79ec
Step 2/2 : RUN yum -y install gcc libmemcached-devel
---> Running in d3b9a6f526d7
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirror.nsw.coloau.com.au
* extras: mirror.nsw.coloau.com.au
* updates: mirror.nsw.coloau.com.au
module.exports={"33088":19991,"33089":20002,"33090":20012,"33091":20053,"33092":20066,"33093":20106,"33094":20144,"33095":20203,"33096":20205,"33097":20220,"33098":20252,"33099":20362,"33100":20479,"33101":20546,"33102":20560,"33103":20600,"33104":20696,"33105":20702,"33106":20724,"33107":20758,"33108":20810,"33109":20817,"33110":20836,"33111":20842,"33112":20869,"33113":20880,"33114":20893,"33115":20902,"33116":20904,"33117":20905,"33118":20935,"33119":20950,"33120":20955,"33121":20972,"33122":20988,"33123":21003,"33124":21012,"33125":21013,"33126":21024,"33127":21035,"33128":21049,"33129":21071,"33130":21105,"33131":21136,"33132":21138,"33133":21140,"33134":21148,"33135":21167,"33136":21173,"33137":21200,"33138":21248,"33139":21255,"33140":21284,"33141":21318,"33142":21343,"33143":21395,"33144":21424,"33145":21469,"33146":21539,"33147":21584,"33148":21585,"33149":21642,"33150":21661,"33185":21667,"33186":21684,"33187":21712,"33188":21795,"33189":21823,"33190":21836,"33191":21843,"33192":21853,"33193":21868,
@robinst
robinst / gh-releases-to-changelog.sh
Created September 8, 2017 05:49
Commands to help convert GitHub releases to CHANGELOG.md
# Get releases for your repository (change the URL and add user/password if necessary)
# If there's more than one page, you might have to do more requests with `?page=2` etc
curl https://api.github.com/repos/:owner/:repo/releases > releases.json
# Use jq! https://stedolan.github.io/jq/
# "v" is a prefix to strip from the release names, might not be necessary
jq -r '.[] | "## [" + (.name | ltrimstr("v")) + "] - " + .created_at[:10] + "\n" + .body' releases.json >> CHANGELOG.md
# Now edit the CHANGELOG.md, see here: http://keepachangelog.com/en/1.0.0/
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:335:20
stack backtrace:
0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
1: std::sys_common::backtrace::_print
2: std::panicking::default_hook::{{closure}}
3: std::panicking::default_hook
4: std::panicking::rust_panic_with_hook
5: std::panicking::begin_panic
6: std::panicking::begin_panic_fmt
7: rust_begin_unwind