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);
@hacksoldier
hacksoldier / moveFile.java
Created September 28, 2015 12:47
Move file from previous to new directory
public void moveFile () throws IOException {
File afile =new File(PDF_NAME_DIRECTORY);
if(afile.renameTo(new File("C:\\dati\\newDirectory\\" + afile.getName()))){
System.out.println("File is moved successful!");
}else{
System.out.println("File is failed to move!");
}
}
@hacksoldier
hacksoldier / writePDFfile.java
Last active October 8, 2015 08:53
How to wirte a simple document in PDF format
import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
public void readFileFromDisk (String path, String fileName){
try{
bufferReader = new BufferedReader(new FileReader("C:\\dati\\fileDiTest.txt"));
StringBuilder sb = new StringBuilder();
String line = bufferReader.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = bufferReader.readLine();
public void writeFileOnDisk (String path, String fileName, String csn){
try{
PrintWriter write = new PrintWriter(path + fileName, csn);
write.println("The first line");
write.close();
} catch (IOException ex) {
log.error("Error in writeFileOnDisk", ex);
} finally {
if(write != null)
write.close();
@hacksoldier
hacksoldier / replaceAll().js
Last active September 29, 2015 12:10
This function is a replaceAll(). Once inserted you can safely do var str = str.replaceAll(); - JavaScript
String.prototype.replaceAll = function (find, replace) {
var str = this;
return str.replace(new RegExp(find, 'g'), replace);
};
@hacksoldier
hacksoldier / BubbleSort.java
Last active September 29, 2015 12:11
BubbleSort
/**
* Bubble Sort with Generics
*/
public void bubbleSort () throws EmptyArrayException {
for(int i=0; i < this.arraySort.length; i++)
for (int j=0; j < this.arraySort.length - 1; j++)
if(this.arraySort[j].compareTo(this.arraySort[j+1]) > 0) {
T key = this.arraySort[j];
this.arraySort[j] = this.arraySort[j+1];
this.arraySort[j+1] = key;
@hacksoldier
hacksoldier / Impostare manualmente una data
Created May 18, 2014 09:52
Impostare manualmente una data
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setDay:11];
[dateComponents setMonth:05];
[dateComponents setYear:2014];
NSDate *date = [[NSDate alloc] init];
date = [dateComponents date];
@hacksoldier
hacksoldier / HeaderDoc
Created May 18, 2014 09:26
Keyword comment Xcode with definition and example
<H2> HeaderDoc Tags Common to All Comment Types </H2>
The tags in the table below can be used in any comment for any data type, function, header, or class.
* @abstract -> A short string that briefly describes a function, data type, and so on. This should not contain multiple lines (because it will look odd in the mini-TOCs). Save the detailed descriptions for the discussion tag.
usage in: block. (single short sentence recommended)
* @apiuid -> Overrides the API UID (apple_ref) associated with this comment.
Note that very little checking is performed on this string. Thus, this tag has the potential to seriously break your output if used incorrectly. It is primarily provided for resolving symbol collisions that are otherwise unavoidable, and is generally discouraged.
usage in: attribute. Must contain no spaces, and must be a valid API reference. See “Symbol Markers for HTML-Based Documentation” for details.
@hacksoldier
hacksoldier / gist:3e3e0cb7fe2bb3194011
Last active August 29, 2015 14:01
KeyWord Comment Xcode
@abstract -> Nome del metodo dal quale è stato estratto questo codice.
@attention -> Warning relativi al metodo.
@author -> Autore del metodo
@brief -> Descrizione del metodo che apparire nella doc rapida.
@bug -> Bug presenti attualmente nel codice.
@code @\endcode
@copyright -> Copyriht del codice
@const -> Costanti che vengono utillizzate all'interno del metodo.
@date -> Data creazione.
@discussion ->