Skip to content

Instantly share code, notes, and snippets.

View melastmohican's full-sized avatar

Mariusz Jurgielewicz melastmohican

  • Bellevue, WA
  • 03:45 (UTC -08:00)
View GitHub Profile
#!/usr/bin/env groovy
def items = [ '1' : [a : 1, b : 2], '2' : [a :1, b: 3], '3' : [a: 0, b :5]]
def mx = items.findAll { k, v -> v.a == 1 }.max { it.value.b }.value.b
println mx
def mx1 = items.max { left, right ->
if(left.value.a == 1 && right.value.a == 1) {
left.value.b <=> right.value.b
} else {
@melastmohican
melastmohican / rtf2md.sh
Created March 22, 2017 23:34
Convert RTF to Markdown on Mac OSX with textutl and pandoc
textutil -convert html -stdout file.rtf | pandoc --from=html --to=markdown --out=file.md
@melastmohican
melastmohican / csvh2.groovy
Created March 31, 2017 23:46
Groovy H2 CSV
#!/usr/bin/env groovy
@Grapes([
@Grab(group = 'com.h2database', module = 'h2', version = '1.4.194'),
@GrabConfig(systemClassLoader=true)
])
import groovy.sql.Sql
import org.h2.Driver
@melastmohican
melastmohican / replace_link.sh
Last active April 6, 2017 17:45
Replacing symbolic links to directory
@melastmohican
melastmohican / find_unzip_all_files.sh
Created April 4, 2017 23:36
Extract all gz in a directory
# This will find files recursively (you can limit it by using some 'find' parameters.
# see the man pages
# Final backslash required for exec example to work
find . -name '*.gz' -exec gunzip '{}' \;
@melastmohican
melastmohican / upack_gz_file.sh
Created April 4, 2017 23:38
Uncompressing gz files
U#sing gunzip command:
gunzip file.gz
ls file
#Using gzip -d command:
gzip -d file.gz
ls file
#If file extension is tar.gz, type the command:
tar -zxvf file.tar.gz
@melastmohican
melastmohican / compress_gz_file.sh
Last active April 5, 2017 21:34
Compress an Entire Directory or a Single File
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
#Here’s what those switches actually mean:
#-c: Create an archive.
#-z: Compress the archive with gzip.
#-v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful.
#-f: Allows you to specify the filename of the archive.
tar -czvf archive.tar.gz stuff
tar -czvf archive.tar.gz /usr/local/something
@melastmohican
melastmohican / diff_or_error.sh
Last active April 7, 2017 22:03
Check if files are different
#!/bin/bash
PREV_FILE=unified_article_processing_outcomes.txt
NEW_FILE=unified_article_processing_outcomes_new.txt
echo Checking for updates...
DIFF=$(diff $PREV_FILE $NEW_FILE)
if [ $? -ne 0 ]
then
@melastmohican
melastmohican / curl.groovy
Last active February 12, 2020 08:33
Download file using curl in groovy
#!/usr/bin/env groovy
def execute(command) {
def proc = command.execute()
def out = new StringBuffer()
def err = new StringBuffer()
proc.consumeProcessOutput(out, err)
proc.waitFor()
if( out.size() > 0 ) println out
@melastmohican
melastmohican / del_ds_store.sh
Last active May 24, 2017 22:10
Delete All DS_Store Files from a Mac
find . -name ".DS_Store" -type f -exec rm {} \;