Skip to content

Instantly share code, notes, and snippets.

View bitsnaps's full-sized avatar
🌍
Working @ CorpoSense

Ibrahim H. bitsnaps

🌍
Working @ CorpoSense
View GitHub Profile
@bitsnaps
bitsnaps / JarUpdater.groovy
Created June 5, 2018 13:50
Update Jar file by adding new ones with 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 / scrape_chinabestprice.groovy
Created August 8, 2018 01:14
Simple groovy crawler from chinabestprice.com
@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 / simple_random_encryption.groovy
Created September 4, 2018 10:18
Groovy simple random encryption
/*
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 / install-wp.sh
Created December 13, 2018 22:14
Wordpress CLI tool (wp-cli) script installation automation
#! /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 / TikaMetadataExtractor.groovy
Created June 19, 2019 21:04 — forked from kaimst/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.
/**
* 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 / matrices.groovy
Created June 21, 2019 20:47
Matrix manipulation with groovy by graxxia library
@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 / sendemail.ppy
Created July 3, 2019 18:57
Send an email using sendinblue service api
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 / wordCounter.groovy
Created July 25, 2019 18:45
Simple wordCounter with Groovy
@groovy.transform.Canonical
class Phrase {
String phrase
Map wordCount() {
words.collectEntries { [ (it): occurrences(it) ] }
}
List getWords() {
@bitsnaps
bitsnaps / HelloJNI.java
Last active November 25, 2019 11:41
Simple example using JNI with MinGW C++
import java.util.*;
class HelloJNI extends Hello {
static {
System.loadLibrary("HelloCpp"); // HelloCpp.dll (Windows) or libhellocpp.so (*nix)
}
//instance variable
private int number = 10;
@bitsnaps
bitsnaps / hsqldb_demo.groovy
Created January 1, 2020 13:59
hsqldb demo example with groovy
@Grab('org.hsqldb:hsqldb:2.3.3')
@GrabConfig(systemClassLoader=true)
import groovy.sql.*
def sql = Sql.newInstance('jdbc:hsqldb:mem:yourDB', 'org.hsqldb.jdbcDriver')
sql.execute '''
CREATE TABLE IF NOT EXISTS Author (
id INTEGER GENERATED BY DEFAULT AS IDENTITY,