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 / 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 / main.cpp
Created June 9, 2016 23:13
Memory and CPU usage (using MinGW in x64 windows machine)
#include <iostream>
#include "windows.h"
//Memory Usage
#include "psapi.h"
//CPU Usage
#include "TCHAR.h"
//1- assuming we are monitoring Windows machine
//2- consider to use Performance Data Helper library which is much more intuitive
@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 / 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 / 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 / ZipUnzip.groovy
Last active September 4, 2021 16:15
Zip and UnZip files using Groovy
import java.util.zip.*
String zipFileName = "file.zip"
String inputDir = "logs"
def outputDir = "zip"
//Zip files
ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(zipFileName))
new File(inputDir).eachFile() { file ->
@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 / 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()