Skip to content

Instantly share code, notes, and snippets.

@esycat
esycat / PrettyPrinter.groovy
Last active December 19, 2023 16:20
A simple way to pretty print nested lists and maps in Groovy.
import static groovy.json.JsonOutput.*
def config = ['test': 'lalala']
println prettyPrint(toJson(config))
@esycat
esycat / README.md
Last active October 30, 2023 10:52
How to get GNU's readlink -f behavior on OS X.

readlink.sh is a pure shell implementation that uses dirname, basename, readlink and pwd utils. Note that you cannot rename it to just readlink as then the script will call itself instead of the system utility.

realpath script simply calls Python's os.path.realpath. Python is provided in OS X and major Linux distributions. You can use instead of the system utility by making a symlink: ln -s realpath readlink.

Another way is to install coreutils package via Homebrew or MacPorts and use greadlink.

The code is taken from the following page on StackOverflow: http://goo.gl/Yw9OY

@esycat
esycat / WEEKDAYOFMONTH.vba
Created July 14, 2019 12:41
A custom function for Excel to find Nth weekday of the month
Function WEEKDAYOFMONTH(month As Date, dow As Integer, offset As Integer)
FirstDayOfMonth = month - Day(month) + 1
LastDayOfMonth = WorksheetFunction.EoMonth(month, 0)
If offset > 0 Then
StartDate = FirstDayOfMonth + offset * 7
adjustment = weekday(FirstDayOfMonth + 7 - dow)
ElseIf offset < 0 Then
StartDate = LastDayOfMonth + (offset + 1) * 7
adjustment = weekday(LastDayOfMonth - dow)
@esycat
esycat / build.gradle
Last active June 6, 2018 21:48
An example Gradle build configuration that shows that `ext` does not always point to the same object as `project.ext`. The assertion on line 10 fails.
assert(project.ext == ext)
// assigning some values just for testing
project.ext.set('a', 'a-val')
ext.set('b', 'b-val')
assert(project.ext == ext)
task test() {
assert(project.ext == ext)
@esycat
esycat / .gitignore
Last active January 17, 2018 00:17
/.gradle/
/build/
/buildSrc/
generated.conf
@esycat
esycat / git-find-unique-commits-nr.sh
Last active June 16, 2017 14:23
Find the number of unique commits since the given date on all remote heads
# N.B. The uniquenes is determined based on `git-patch-id` that is simply a hash of the diff
since="2016-07-01"
for c in $(git log --since="${since}" --remotes --format="%H") ; do git show $c | git patch-id ; done | sort -u | wc -l
@esycat
esycat / .gitignore
Last active January 1, 2016 09:08
MinifyJsTask doesn't work from an included file https://github.com/eriwen/gradle-js-plugin/issues/61
.gradle
build
main.min.js
@esycat
esycat / indent.sh
Created September 27, 2013 06:16
indent params
TAB_SIZE=4
LINE_LENGTH=120
indent \
--no-tabs \
--tab-size${TAB_SIZE} \
--line-length${LINE_LENGTH} \
--space-after-cast \
--braces-on-if-line \
--braces-on-func-def-line \
@esycat
esycat / .vimrc
Last active December 15, 2015 15:08
My Vim config file.
" Don't be compatible with Vi
set nocompatible
" Indentation style
set autoindent
"set smartindent
"set cindent
" Tab behavior
set tabstop=4
@esycat
esycat / yay-time.sql
Last active August 29, 2015 14:05
For Tim & Marley with Love :-)
SELECT
DATABASE(), table_name, column_name, data_type,
CONCAT(
"UPDATE ", table_name,
" SET ", column_name, " = CONVERT_TZ(", column_name, ", 'UTC', 'Australia/Sydney')",
" WHERE ", column_name, " > '2014-08-05 22:00:00';"
) AS query
FROM information_schema.columns
WHERE
table_schema = DATABASE()