Skip to content

Instantly share code, notes, and snippets.

@bodiam
bodiam / gist:5795800
Last active January 30, 2019 22:05
A small description of my use case for Groovy data classes.
// Current way in Groovy
@Immutable
class Person {
String firstName, lastName
int age
Date dateCreated
}
// But: This would be nice
data class Person(String name, String lastName, int age, Date dateCreated)
@bodiam
bodiam / gist:5998377
Last active December 19, 2015 18:28 — forked from erdi/gist:5998112
Gradle script to prints the file location of the produced artifact. Can be put in ~/.gradle/init.gradle so it can be used across projects.
allprojects {
tasks.withType(AbstractArchiveTask) { task ->
outputs.upToDateWhen { false }
task.doLast {
println "\nOutput location: ${archiveName}\n"
}
}
}
@bodiam
bodiam / gist:5999047
Last active December 19, 2015 18:29
Marcin is a crazy fish.
def artifacts = []
addListener(new TaskExecutionAdapter() {
void afterExecute(Task task, TaskState state) {
if(task in AbstractArchiveTask) {
artifacts << task.outputs.files.singleFile
}
}
})
// querying and cursors
cursor = db.people.find(); null ;
cursor.hasNext() // returns true (if there is another set of results) and false (if not)
cursor.next() // returns the next result and move the cursor foward
// Limiting the set of results returned by the queries
cursor.limit(5); null; // limit the results returned by the cursor (default is 20)
// note: the 'null' keyword is used to prevent the mongoshell from printing that query out
@bodiam
bodiam / gist:6376782
Created August 29, 2013 11:10
Bash script to show the name of branch per module.
#!/bin/bash
txt_green=$(tput setaf 2)
txt_purple=$(tput setaf 5)
txt_reset=$(tput sgr0)
for i in */
do
cd $i
git_branch=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1'/`
@bodiam
bodiam / gist:6376802
Created August 29, 2013 11:14
Git branchname of current module displayed in bash shell. Add this to .bashrc
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
function proml {
local BLUE="\[\033[0;34m\]"
# OPTIONAL - if you want to use any of these other colors:
local RED="\[\033[0;31m\]"
@bodiam
bodiam / dict_to_object.py
Last active December 22, 2015 02:59
Transforming a dict to objects in Python
class Light:
def __init__(self, id, name):
self.id = id
self.name = name
response = {"1": {"name": "bedroom"}, "2": {"name": "kitchen"}}
lights = [Light(id, response[id]["name"]) for id in response]
@bodiam
bodiam / object_to_json_mapping.py
Created September 2, 2013 19:15
Simple Python object to JSON mapping
import json
class Light:
def __init__(self, id, name):
self.id = id
self.name = name
lights = [Light("1", "bedroom"),Light("2","kitchen")]
@bodiam
bodiam / gutenberg_rsync.sh
Created September 8, 2013 18:51
This script mirrors the gutenberg cache of generated file formats.
#!/bin/bash
# This script mirrors the gutenberg cache
# of generated file formats
# By Braddock Gaskill 2013
DIR=/knowledge/data/gutenberg/cache/generated
mkdir -p "${DIR}"
cd "${DIR}"
pwd
while (true); do
@bodiam
bodiam / not_working_sudo_in_java
Created September 9, 2013 23:14
A sudo example for stackoverflow. Note that this on is NOT working.
public static void main(String[] args) throws IOException {
Process pb = new ProcessBuilder("sudo", "ls").start();
OutputStream out = pb.getOutputStream();
out.write(password.getBytes());
String line;
BufferedReader input = new BufferedReader(new InputStreamReader(pb.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}