Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

bitsnaps bitsnaps

🏠
Working from home
Block or report user

Report or block bitsnaps

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bitsnaps
bitsnaps / wordCounter.groovy
Created Jul 25, 2019
Simple wordCounter with Groovy
View wordCounter.groovy
@groovy.transform.Canonical
class Phrase {
String phrase
Map wordCount() {
words.collectEntries { [ (it): occurrences(it) ] }
}
List getWords() {
@bitsnaps
bitsnaps / sendemail.ppy
Created Jul 3, 2019
Send an email using sendinblue service api
View sendemail.ppy
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:
@bitsnaps
bitsnaps / matrices.groovy
Created Jun 21, 2019
Matrix manipulation with groovy by graxxia library
View matrices.groovy
@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)
@bitsnaps
bitsnaps / TikaMetadataExtractor.groovy
Created Jun 19, 2019 — forked from kaisternad/TikaMetadataExtractor.groovy
A Groovy script that extracts metadata from files using Apache Tika. Works recursively on a file hierarchy and writes all found metadata into a single xml file.
View TikaMetadataExtractor.groovy
/**
* 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,
@bitsnaps
bitsnaps / install-wp.sh
Created Dec 13, 2018
Wordpress CLI tool (wp-cli) script installation automation
View install-wp.sh
#! /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
@bitsnaps
bitsnaps / simple_random_encryption.groovy
Created Sep 4, 2018
Groovy simple random encryption
View simple_random_encryption.groovy
/*
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()
}
@bitsnaps
bitsnaps / scrape_chinabestprice.groovy
Created Aug 8, 2018
Simple groovy crawler from chinabestprice.com
View scrape_chinabestprice.groovy
@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){
@bitsnaps
bitsnaps / JarUpdater.groovy
Created Jun 5, 2018
Update Jar file by adding new ones with Groovy
View JarUpdater.groovy
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')
@bitsnaps
bitsnaps / JarMaker.groovy
Created Jun 3, 2018
Create a Jar file programatically using Groovy
View JarMaker.groovy
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 {
@bitsnaps
bitsnaps / HelloAwt.groovy
Created Jun 3, 2018
Simple AWT Gui App using what looks like Builder Pattern with Groovy
View HelloAwt.groovy
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}())
You can’t perform that action at this time.