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 / compile.bat
Last active July 13, 2016 10:38
Groovy JNAerator example using JNA and BridJ
@echo off
REM Compile script on Windows machine
echo Compiling C
gcc -c -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" hello.c
echo Generating o library
gcc -Wl,--add-stdcall-alias -shared -o hello.dll hello.o
echo Generate header interface using JNAcreator
java -jar jnaerator.jar -mode Jar -jar hello.jar -runtime JNA -library hello hello.h
rem java -jar jnaerator.jar -mode Jar -jar hello.jar -runtime BridJ -library hello hello.h
echo Running groovy script
@bitsnaps
bitsnaps / GMahout.groovy
Last active November 29, 2016 14:19 — forked from rahulsom/Ele.groovy
Mahout with Groovy - the faster way
@Grab(group = 'org.apache.mahout', module = 'mahout-core', version = '0.9')
import org.apache.mahout.cf.taste.impl.common.FastByIDMap
import org.apache.mahout.cf.taste.impl.common.FastIDSet
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel
import org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender
import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity
//you can get this data from here: http://files.grouplens.org/datasets/movielens/ml-100k.zip
def mlDir = new File(getClass().protectionDomain.codeSource.location.path).parent+'/ml-100k'
@bitsnaps
bitsnaps / LoginForm.groovy
Created December 27, 2016 14:03
Simple LoginForm using GroovyFX
/**
* Original JavaFX tutorial:
* http://docs.oracle.com/javafx/2/get_started/form.htm
* Tested using JDK8
*/
@Grab('org.codehaus.groovyfx:groovyfx:0.4.0')
//@GrabExclude('org.codehaus.groovy:groovy-all')
import static groovyx.javafx.GroovyFX.start
@bitsnaps
bitsnaps / SimpleStringEncryption.java
Created June 29, 2017 08:59
encrypt & decrypt randomly strings
class SimpleStringEncryption {
public static String encrypt(String str){
int code;
String result = "";
for (int i = 0; i < str.length(); i++) {
code = Math.round((float) Math.random()*8+1);
result += code + Integer.toHexString( ((int) str.charAt(i) ) ^ code )+"-";
}
return result.substring(0, result.lastIndexOf("-"));
@bitsnaps
bitsnaps / Encryptor.java
Last active July 28, 2017 10:23
Simple AES/DES Encryption & Decryption with no extra library
//Separate file for simple AES encrypt/decrypt
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
public class Encryptor {
public static String encrypt(String key, String initVector, String value) {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
@bitsnaps
bitsnaps / build.bat
Last active March 25, 2018 16:35
Groovy and JNA simple example (C & C++ on Win64bit)
@echo off
echo Compiling C/C++
REM C library
gcc -Wl,--add-stdcall-alias -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" -shared -o helloc.dll hello.c
REM C++ library
g++ -Wl,--add-stdcall-alias -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" -shared -o hellocpp.dll hello.cpp
echo Running groovy script
@bitsnaps
bitsnaps / GFoenix.groovy
Last active May 12, 2018 15:32
GroovyFX using JFoenix simple login example
@Grapes([
@Grab('org.codehaus.groovyfx:groovyfx:0.4.0'),
@Grab('com.jfoenix:jfoenix:8.0.3')
])
import static groovyx.javafx.GroovyFX.start
import com.jfoenix.controls.*
start {
// you could use registerBeanFactory or use node()
@bitsnaps
bitsnaps / JarExtractor.groovy
Created June 2, 2018 18:08
Extract Jar file pragmatically with Groovy
/*
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}"
@bitsnaps
bitsnaps / HelloAwt.groovy
Created June 3, 2018 11:42
Simple AWT Gui App using what looks like Builder Pattern with 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}())
@bitsnaps
bitsnaps / JarMaker.groovy
Created June 3, 2018 18:27
Create a Jar file programatically using 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 {