Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View gipi's full-sized avatar
😎
code for food

Gianluca Pacchiella gipi

😎
code for food
View GitHub Profile
@gipi
gipi / gist:1336772
Created November 3, 2011 15:26
Add HTML5 support in IE<9
<head>
<meta charset="utf-8" />
<title>My Weblog</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
@gipi
gipi / gist:1345558
Created November 7, 2011 17:16
Hineritance in Javascript by __proto__ property
// source: <http://www.2ality.com/2011/11/javascript-classes.html>
var PersonProto = {
describe: function () {
return "Person called " + this.name;
},
};
var jane = {
__proto__: PersonProto,
name: "Jane",
};
@gipi
gipi / gist:1385287
Created November 22, 2011 09:28
Simple python script to strip not whitelisted tags from a stream
import re, sys
for line in sys.stdin:
print re.sub(r"<(?![ ]*/?[ ]*(p|br)\b)[^>]*>", "", line)
@gipi
gipi / gist:1385644
Created November 22, 2011 13:19
Create a module in Javaascript
var basketModule = (function() {
var basket = []; //private
return { //exposed to public
addItem: function(values) {
basket.push(values);
},
getItemCount: function() {
return basket.length;
},
getTotal: function(){
@gipi
gipi / gist:1386262
Created November 22, 2011 17:20
Deserialize XML into Java objects
XStream xstream = new XStream();
// http://stackoverflow.com/questions/3136234/xstream-root-as-a-collection-of-objects/3138114#3138114
xstream.alias("products", List.class);
xstream.alias("product", Product.class);
xstream.useAttributeFor(Product.class, "id");
List<Product> ps = (List<Product>)xstream.fromXML("<products><product id=\"1\"><name>Gatti</name><descriptionShort>Pelosi e caldi</descriptionShort></product><product id=\"2\"><name>Cani</name><descriptionShort>Abbaiano</descriptionShort></product></products>");
Iterator<Product> i = ps.iterator();
while (i.hasNext()) {
@gipi
gipi / gist:1388360
Created November 23, 2011 10:33
Simple code to do HTTP GET/POST requests in Java
import org.apache.http.*;
import org.apache.http.util.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.*;
protected HttpResponse doPost() throws java.io.IOException {
HttpClient client = new DefaultHttpClient();
@gipi
gipi / gist:1388419
Created November 23, 2011 10:52
Shell script to generate HMAC of a message
function get_hmac() {
message=$1
shared_key=$2
echo -n "$message" | openssl dgst -md5 -hmac "${shared_key}"
}
@gipi
gipi / gist:1388784
Created November 23, 2011 14:22
Convert byte array to an hex String
byte[] messageDigest = algorithm();
StringBuffer hexString = new StringBuffer();
for (int i=0;i<messageDigest.length;i++) {
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
}
return hexString.toString();
@gipi
gipi / ImageViewExtended.java
Created November 25, 2011 14:56
Android: class to download remote resources and implemente Observer pattern and a simple extension of ImageView that use it.
package com.example.android;
import android.content.Context;
import android.widget.ImageView;
import android.util.AttributeSet;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation;
@gipi
gipi / compose.c
Created November 28, 2011 21:14
#gstreamer: use gnlcomposite to concatenate videos passed as argument
/*
* http://gstreamer-devel.966125.n4.nabble.com/How-to-concatenate-video-files-td967232.html
* $ gcc `pkg-config --cflags --libs gstreamer-0.10` compose.c -o gst_compose
*/
#include <stdio.h>
//#include <tchar.h>
#include <gst/gst.h>
GstElement *pipeline, *conv, *sink, *comp;