Skip to content

Instantly share code, notes, and snippets.

View rmorenobello's full-sized avatar

Raúl Moreno Bello rmorenobello

View GitHub Profile
import org.apache.commons.io.FilenameUtils;
String fileNameWithOutExt = FilenameUtils.getBaseName(fileNameWithExt);
// or
String fileNameWithOutExt = FilenameUtils.removeExtension(fileNameWithExt);
// Tutorial on File: http://tutorials.jenkov.com/java-io/file.html
def getFileWithPath = { rutaCarpeta, nom ->
def homePath = System.getProperty('user.home').replace('\\','/')
println "home Path: " + homePath
def directory = new File(homePath.concat("/${rutaCarpeta}/"))
if(!directory.exists()){
boolean dirCreated = directory.mkdirs()
assert dirCreated
}
@rmorenobello
rmorenobello / setSystemPropertyFromCLI.groovy
Last active November 2, 2020 04:46
How to set and retrieve JVM system variables when running java/groovy from CLI
// http://stackoverflow.com/questions/8098564/is-it-possible-to-specify-java-system-properties-when-running-groovy-from-comman
/*
System properties are set on the java command line using the
java -Dpropertyname=value
syntax.
They can also be added at runtime using
System.setProperty(name, value)
or via the various
System.getProperties().load()
methods.
@Grab(group = 'net.sf.opencsv', module = 'opencsv', version = '2.3')
import au.com.bytecode.opencsv.CSVReader
import au.com.bytecode.opencsv.CSVParser
import au.com.bytecode.opencsv.CSVWriter
def TEST_FILE_NAME = 'test.csv'
def TEST_OUTPUT_FILE_NAME = 'testOut.csv'
List<String[]> rows = new CSVReader(new FileReader(new File(TEST_FILE_NAME)), CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_ESCAPE_CHARACTER, CSVParser.DEFAULT_QUOTE_CHARACTER, 1).readAll()
// to filter the resultSet:
@rmorenobello
rmorenobello / JVMSystemProperties.java
Last active February 14, 2018 10:45
Set and Retrieve system (JVM) and environment (OS) variables in java and groovy
// Java System properties
// =======================
// http://docs.oracle.com/javase/tutorial/essential/environment/properties.html
// http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
/*
Key Meaning
================
"file.separator" Character that separates components of a file path. This is "/" on UNIX and "\" on Windows.
"java.class.path" Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the path.separator property.
"java.home" Installation directory for Java Runtime Environment (JRE)
@rmorenobello
rmorenobello / OSEnvVars.java
Created February 28, 2015 00:03
Set and Retrieve environment (OS) variables in java
// OS Environment Variables
// =======================
// http://docs.oracle.com/javase/tutorial/essential/environment/env.html
/*
Windows provides the user name in an environment variable called USERNAME,
while UNIX implementations might provide the user name in USER, LOGNAME, or both.
To maximize portability, if the env var you need is available as java system property, always use getProperty().
For example, if the operating system provides a user name, it will always be available in the system property user.name.
*/
@rmorenobello
rmorenobello / getRunningScriptFullPath.groovy
Created February 28, 2015 00:46
Get the full system path of the running groovy script from itself
// http://stackoverflow.com/a/1169196/2906290
/*
when calling
c:\scripts\MyScript.groovy from c:\users\Scott\
I wanted to know c:\scripts\.
*/
def scriptFile = getClass().protectionDomain.codeSource.location.path
def scriptDir = new File(scriptFile).parent
-- MySQL
http://kedar.nitty-witty.com/blog/search-through-all-databases-tables-columns-in-mysql
#kedar.nitty-witty.com
## Table for storing resultant output
DROP TABLE IF EXISTS `temp_details`;
CREATE TABLE `temp_details` (
`t_schema` varchar(45) NOT NULL,
@rmorenobello
rmorenobello / ASUS laptops:How to load BIOS.txt
Last active April 22, 2022 11:28
ASUS laptops: How to load BIOS screen and allow booting from USB device
ASUS laptop (for Windows 8 at least)
===========
1st version for entering the BIOS:
1. Shut down your Asus laptop. Click "Start" then click the "Shut down" button.
2. Power your computer back on.
3. Wait for the ASUS splash screen.
4. Press the "ALT" and "F2" keys on your keyboard as soon as you see the ASUS splash screen. Your computer will enter the BIOS.
@rmorenobello
rmorenobello / copyFilteredFileStructure.groovy
Created May 11, 2015 20:43
Recorrer directorios, archivos y copiarlos con AntBuilder.copy()
// http://omarello.com/2010/09/groovy-to-the-rescue/
static void moveDocumentationToMe(pathToFolder, groupId) {
// move everything to my desktop, of course i could have passed as an argument,
// but i don't really care for now
FileSystemView filesys = FileSystemView.getFileSystemView()
def destinationDir = filesys.getHomeDirectory().getCanonicalPath()
//paranoia <img src="http://omarello.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley">
if (!destinationDir.endsWith(File.separator))