Skip to content

Instantly share code, notes, and snippets.

View kdabir's full-sized avatar
👨‍💻
go git it

Kunal Dabir kdabir

👨‍💻
go git it
View GitHub Profile
@kdabir
kdabir / check_and_extract.groovy
Created May 21, 2012 15:17
finding regex matches in text in groovy
def m = "1234 abc" =~ /^(\d+)/
def n = "abc 1234" =~ /^(\d+)/
println (m.find()?m.group():"not matched")
println (n.find()?n.group():"not matched")
@kdabir
kdabir / homebrew_maintenance.md
Last active March 3, 2024 21:12
HomeBrew Maintenance (Mac OS X)

HomeBrew Maintenance

  • To list all the software/lib installed by brew $ brew list

  • to update an app $ brew upgrade appname

  • to see issues $ brew doctor

  • to update brew $ brew update

@kdabir
kdabir / heredoc_json.bash
Last active January 11, 2024 02:25
json in heredoc in bash script alongwith variable substitution
_BUCKET_NAME="foo.example.com"
_POLICY=$(cat <<EOT
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"PublicReadForGetBucketObjects",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
@kdabir
kdabir / inline.groovy
Created September 27, 2014 17:53
Groovy List Destructuring
def (a,b,rest) = [0, 1, 2..-1].collect { [1,2,3,4][it] }
assert a == 1
assert b == 2
assert rest == [3,4]
@kdabir
kdabir / get_content.groovy
Created February 22, 2012 13:04
get content from url and write to a file in groovy
// saving from url to a file (append)
new File("output.xml") << new URL ("http://some.url/some/path.xml").getText()
@kdabir
kdabir / iso_date.groovy
Last active January 20, 2023 19:15
current date in iso 8601 in groovy
new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC"))
@kdabir
kdabir / log4j.properties
Created March 14, 2012 14:17
a minimal log4j config file
log4j.rootLogger=INFO, CONSOLE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%-5p] %m%n
# a more detailed PatternLayout: %d [%t] %-5p %c - %m%n
# adjust specific logger levels as per the need to control the verbosity of logs
@kdabir
kdabir / dir_traverse.groovy
Last active December 6, 2022 08:12
A groovy directory traverse that excludes given dirs. Change the last closure to do something interesting instead of printing the dir name
import groovy.io.FileType
import groovy.io.FileVisitResult
final excludedDirs = ['.svn', '.git', '.hg', '.idea', 'node_modules', '.gradle', 'build']
int count = 0
new File(root).traverse(
type : FileType.DIRECTORIES,
preDir : { if (it.name in excludedDirs) return FileVisitResult.SKIP_SUBTREE }, // excludes children of excluded dirs
excludeNameFilter : { it in excludedDirs }, // excludes the excluded dirs as well
@kdabir
kdabir / mac_setup.md
Last active November 24, 2022 21:39
Clean Setup on Mac

Cleaning up the mac

Before formatting/wiping out all the data

@kdabir
kdabir / replace_quotes.groovy
Created September 22, 2012 14:35
Replace quotes from string in groovy
println """
some "text" with quotes
""".replaceAll (/\"/,/\\\"/)