Skip to content

Instantly share code, notes, and snippets.

View RaffaeleSgarro's full-sized avatar

Raffaele Sgarro RaffaeleSgarro

View GitHub Profile
@RaffaeleSgarro
RaffaeleSgarro / Hexdump.java
Created April 7, 2013 11:03
Print a hexdump of a string
package stackoverflow;
public class Hexdump {
public static void main(String[] args) {
// This is mocked. Get the actual filename
String filename = "Qwertypsadfksadf";
// Log the hexdump
System.out.println(hexdump(filename));
}
@RaffaeleSgarro
RaffaeleSgarro / php_to_js.php
Last active December 26, 2015 20:19
Pass PHP variables to the client Javascript. Handle untrusted input both when feeding the Javascript and when updating the DOM
<html>
<head>
<script src="jquery-2.0.3.min.js"></script>
<script src="underscore-min.js"></script>
<script src="mustache.js"></script>
<script>
$(function(){
$('.btn').click(function(e) {
var user = $.parseJSON( _.unescape( $(this).next().text() ) );
public class ArtifactsWhenUsingDialogFont {
public static void main(String... args) throws Exception {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(PrintServiceLookup.lookupDefaultPrintService());
job.setPrintable(new Printable(){
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
graphics.translate( (int) pageFormat.getImageableX(), (int) pageFormat.getImageableY() );
@RaffaeleSgarro
RaffaeleSgarro / .htaccess
Last active August 29, 2015 13:56
Simple breadcrumb for PHP scripts apps deployed by mapping request paths to the server's filesystem
RewriteEngine On
RewriteRule index.php index.php [END]
RewriteRule (.*) index.php?request=$1 [END]
@RaffaeleSgarro
RaffaeleSgarro / PlotBandCalculator.java
Created July 14, 2014 19:35
GWT/Highchart highlight a plot band
package stackoverflow;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class PlotBandCalculator {
private int hourStart, lengthInHours;
@RaffaeleSgarro
RaffaeleSgarro / Acceptable.java
Created November 23, 2014 09:02
Java LazyIterator
package stackoverflow;
public interface Acceptable {
boolean accept();
}
package stackoverflow;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@RaffaeleSgarro
RaffaeleSgarro / App.java
Created March 31, 2015 17:58
Demo JOOX program
package app;
import org.joox.JOOX;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
@RaffaeleSgarro
RaffaeleSgarro / add_to_whitelist.py
Created April 15, 2015 09:27
Add user to whitelist
#!/usr/bin/env python
# Usage add_to_whitelist.py $FILENAME $USERNAME
import sys
def eval_line(line):
if line.startswith('#'):
return line
if '=' in line:
key, val = line.split('=')
if key == 'app.store.access.list':
@RaffaeleSgarro
RaffaeleSgarro / RhinoHowToReadJavascriptNumbersFromJavaMethod.java
Created May 12, 2015 21:36
Rhino: read Javascript numbers returned from Java method
package stackoverflow;
import sun.org.mozilla.javascript.internal.Context;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.util.Date;
/*
* See question at http://stackoverflow.com/q/30185079/315306