Skip to content

Instantly share code, notes, and snippets.

@davidmoten
davidmoten / script.sh
Last active September 3, 2019 08:56
How to include a java class with main method in a bash script
#!/bin/bash
set -e
TEMPFILE=`mktemp /tmp/ScriptXXXXX|sed -e 's/\.//g'`
CLASS_NAME=`basename "$TEMPFILE"`
JAVA_SOURCE=$TEMPFILE.java
cat <<EOF >$JAVA_SOURCE.tmp
//Write your java class here with a main method
//Be sure to leave the name of the class as Script
@davidmoten
davidmoten / install-ubuntu.sh
Last active January 11, 2017 20:00
ubuntu 14.04 packages install
sudo apt-get install -y curl
sudo apt-add-repository -r http://ppa.launchpad.net/adamsutton/tvheadend
sudo add-apt-repository -y ppa:webupd8team/java
sudo add-apt-repository -y "deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main"
curl http://apt.tvheadend.org/repo.gpg.key | sudo apt-key add -
sudo apt-add-repository -y http://apt.tvheadend.org/stable
sudo apt-get update
@davidmoten
davidmoten / gist:e6d630ae2b2c8cf91a34
Created June 25, 2014 12:09
distance travelled calculator - using sort
/**
* Returns distinct cells and the the total nautical miles travelled in that
* cell. Uses RxJava {@link Observable}s to maximize throughput and will
* scale to use all available processors and to handle a large number of
* files (number of open file handles should be limited by number of
* available processors).
*
* @param files
* @return
*/
@davidmoten
davidmoten / setup-docker.sh
Created September 24, 2014 00:58
setup docker on ubuntu
$!/bin/bash
sudo apt-get purge docker.io
curl -s https://get.docker.io/ubuntu/ | sudo sh
@davidmoten
davidmoten / gist:b52683a278778e16d029
Last active November 28, 2023 22:22
How to contribute to a project on GitHub

How to contribute to a project on GitHub

Fork the project to your account

Login to github, go to project and click on Fork

Clone from fork to local

git clone https://github.com/davidmoten/RxJava.git

Locally add the upstream project

git remote add upstream https://github.com/ReactiveX/RxJava.git

@davidmoten
davidmoten / gist:2770617cee2304d4a0c5
Last active August 29, 2015 14:07
cloud9 maven setup script
sudo add-apt-repository -y ppa:webupd8team/java
sudo add-apt-repository -y "deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main"
sudo apt-get update
sudo apt-get install maven3 --force-yes
cd
echo >>.bashrc
echo export PATH=/usr/share/maven3/bin/mvn:$PATH >>.bashrc
echo alias i=\'mvn clean install\' >>.bashrc
source .bashrc
@davidmoten
davidmoten / gist:346f6c16847d69942cf1
Last active August 29, 2015 14:08
count non comment non blank lines of source for java
find . -name *.java|grep -v target|xargs sed '/^\s*\/\//d;/^\s*$/d'|wc -l
# shows uncommitted files and unpushed commits
function gits {
set -e
git status -s
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
UNPUSHED=`git log origin/$CURRENT_BRANCH..$CURRENT_BRANCH`
if [ -z $UNPUSHED ]; then
echo Unpushed:
echo $UNPUSHED
fi
@davidmoten
davidmoten / gist:de069c45ecbd01e8bd5a
Last active August 29, 2015 14:11
rxjava example
Observable<Entry<GeoCircleValue<String>> results = tree.search(...);
results
    //get just the name of the city
    .map( entry -> entry.value().value)
    //get the populations asynchronously
    .flatMap(name -> Observable.just(name)
                               .map(n -> new NameAndPop(n, service.populationOf(n))
                               .subscribeOn(Schedulers.io()))
 //observe the results on current thread