This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Original Java Code from here: | |
https://stackoverflow.com/questions/1529611/how-to-write-a-java-program-which-can-extract-a-jar-file-and-store-its-data-in-s | |
*/ | |
import java.util.jar.* | |
def jar = new JarFile("path/to/MyLib.jar") | |
def jarFile = new File(jar.name) | |
def distDir = "${jarFile.parent+File.separator}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.* | |
import java.awt.event.* | |
new Frame(title:"Hello AWT", size:[300, 200], locationRelativeTo: null, visible: true).with { | |
def tf = add({ new TextField(text:"www.google.com", bounds: [50,50,150,20])}() ) | |
def l = add({ new Label(bounds: [50,100,250,20]) }()) | |
add({ | |
def b = new Button(label:"Find IP", bounds: [50,150,60,30]) | |
b.addActionListener({ l.text = "IP of ${tf.text} is ${java.net.InetAddress.getByName(tf.text).hostAddress}" }) | |
b}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.jar.* | |
def outputFile = "MyLib.jar" | |
def distDir = "path/to/content/MyLib" | |
/*Manifest manifest = new Manifest() | |
manifest.mainAttributes[Attributes.Name.MANIFEST_VERSION] = "1.0"*/ | |
def jar = new JarOutputStream(new File("${new File(distDir).parent}/${outputFile}").newOutputStream()/*, manifest*/) | |
new File(distDir).eachFileRecurse { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.jar.* | |
def outputFile = new File("path/to/mylib/MyLib.jar") | |
def newFile1 = new File("path/to/new/file/NewClass1.class") | |
def newFile2 = new File("path/to/new/file/NewClass2.class") | |
updateJarFile(outputFile, newFile1, newFile2) | |
def updateJarFile(File jarFile, File... files){ | |
def tmpFile = File.createTempFile('tempJar', '.tmp') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('org.jsoup:jsoup:1.11.2') | |
import org.jsoup.* | |
import org.jsoup.nodes.* | |
import org.jsoup.select.* | |
import groovy.json.* | |
class Main { | |
static main(args){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
groovy equivalent of java encryption snippet: | |
https://gist.github.com/bitsnaps/9cea5e16e09065d20c22db6a4d15cb65 | |
*/ | |
def encrypt(def str){ | |
str.collect{s -> (Math.random()*9+1 as int).with{"${it}${((s.toCharacter() as int^it) as byte[]).encodeHex()}"} }.join('-') | |
} | |
def decrypt(def str){ | |
str.split('-').collect{((it[1..2].decodeHex()[0] as int)^ it[0] as int) as char}.join() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Script tested on MacOS 10.14 with Wordpress 5.0 | |
# Original article at: | |
# https://deliciousbrains.com/automating-local-wordpress-site-setup-scripts/ | |
# Usage: | |
# ./install-wp.sh MyNewSite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2013 Kai Sternad | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('org.graxxia:graxxia:1.0.1') | |
import graxxia.* | |
def m = new Matrix([[3,4,5],[6,2,3]]) | |
println(m) | |
def m1 = [[1,2,3],[2,6,3],[7,4,2]] as Matrix | |
def m2 = [[2,6,4],[2,3,5],[7,6,5]] as Matrix | |
def m3 = [[2,3,4],[8,6,2],[10,4,3]] as Matrix | |
println(m1*2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stderr | |
import requests | |
# make sure this example works | |
# curl -s http://api.coindesk.com/v1/bpi/currentprice.json | python -c "import json, sys; print(json.load(sys.stdin)['bpi']['USD']['rate'])" | |
def send_email(): | |
resp = requests.post('https://api.sendinblue.com/v2.0/email', headers={'api-key':'YOUR_API_KEY'}, | |
json={"to":{"useremail@provider.com":"FULL NAME"}, "from":["youremail@provider.com","Your Full Name"], "subject":"Your Solution","html":"Welcome to <h1>Solution</h1>"}) | |
if resp: #.status_code==200: |