Skip to content

Instantly share code, notes, and snippets.

View hacksoldier's full-sized avatar

Marco Velluto hacksoldier

  • Milan, Italy
View GitHub Profile
public byte[] getByteFromFile(File file) throws IOException, FileTooBigException {
if (file.length() > MAX_FILE_SIZE) {
throw new FileTooBigException(file);
}
ByteArrayOutputStream ous = null;
InputStream ios = null;
try {
byte[] buffer = new byte[4096];
ous = new ByteArrayOutputStream();
ios = new FileInputStream(file);
private ArrayList<File> importFileFromPath(String forderPath)
{
ArrayList<File> files = new ArrayList<>();
File folder = new File(forderPath);
File[] listOfFile = folder.listFiles();
for (int i = 0; i < listOfFile.length; i++)
{
if (listOfFile[i].isFile())
{
@hacksoldier
hacksoldier / FindTypeFieldFromAllDb.sql
Last active October 1, 2015 08:12
Funzione per trovare tutti i capi di tutte le tabelle su tutto il db.
#Databse: Microsoft SQL Server.
USE <database_name>
GO
SELECT table_name 'table_name',
column_name 'Column Name',
data_type 'Data Type',
CHARacter_maximum_length 'Maximum Length'
FROM information_schema.columns
WHERE data_type = <Type to field>
@hacksoldier
hacksoldier / convertDocToHTML.java
Last active March 1, 2016 11:48
Metodo per prendere e convertire un file doc in HTML. Il file verrà restituito tramite string.
/**
* Copyright (c) 2015 Marco Velluto
* Warning! It only works with doc files, but NOT working with .docx
*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hwpf.HWPFDocumentCore;
INSERT INTO xtb_comune(`CODICE_CATASTALE`, `CAP`, `CAPOLUOGO`, `CODICE_ISTAT`, `COMUNE`, `ENABLED`, `POSITION`, `REGIONE`, `SIGLA_PROVINCIA`) VALUES
('A089','92100','Agrigento','84001','Agrigento',true,'74','Sicilia','AG'),
('A181','92010','Agrigento','84002','Alessandria della Rocca',true,'146','Sicilia','AG'),
('A351','92021','Agrigento','84003','Aragona',true,'294','Sicilia','AG'),
('A896','92010','Agrigento','84004','Bivona',true,'731','Sicilia','AG'),
('B275','92010','Agrigento','84005','Burgio',true,'1012','Sicilia','AG'),
('B377','92010','Agrigento','84006','Calamonaci',true,'1078','Sicilia','AG'),
('B427','92010','Agrigento','84007','Caltabellotta',true,'1120','Sicilia','AG'),
('B460','92020','Agrigento','84008','Camastra',true,'1147','Sicilia','AG'),
('B486','92022','Agrigento','84009','CamMarcheata',true,'1169','Sicilia','AG'),
@hacksoldier
hacksoldier / AES.java
Created March 1, 2016 08:21 — forked from dweymouth/AES.java
A Java class to perform password-based AES encryption and decryption
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <dweymouth@gmail.com> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. D. Weymouth 4/2014
* ----------------------------------------------------------------------------
*/
import java.io.*;
/**
* Copyright (c) 2016 Marco Velluto
* @since Java 1.8
* @dependency: <groupId>joda-time</groupId>
*/
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Copyright (c) 2016 Marco Velluto
* @since Java 1.8
* @dependency: <groupId>joda-time</groupId>
*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@hacksoldier
hacksoldier / EncryptionUtil.java
Created March 2, 2016 17:09
Simple Encryption and Decryption java class
package it.reexon.reexon.lib.crypt;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.KeyPair;
extension String {
func md5() -> String! {
let str = self.cStringUsingEncoding(NSUTF8StringEncoding)
let strLen = CUnsignedInt(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
let digestLen = Int(CC_MD5_DIGEST_LENGTH)
let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
CC_MD5(str!, strLen, result)
var hash = NSMutableString()