How to verify the Http-Compression of Static-Content

July 12, 2011 Leave a comment

I know this can be done with Fiddler or Firebug, but i wanted something more faster and simpler, and also it was a perfect excuse for writing my first ruby script. You pass the url, the port, and the path to the element you want to check, and you are done.

Sample run against http://www.ioactive.com/affiliateImg.js

./IsCompressed.rb www.ioactive.com 80 /affiliateImg.js

  WebSite: www.ioactive.com:80
  Path: /affiliateImg.js

  Compression: NO,	1217 bytes,	message: OK ,	code: 200

And the code:

#!/usr/bin/env ruby

require 'net/http'

if ARGV.length != 3
  puts "Mode of Use: script [WebSite] [Port] [Path]"
  exit 1
end

website = ARGV[0]
port = ARGV[1]
path = ARGV[2]

puts "\n"
puts "\tWebSite: " + ARGV[0] + ":" + ARGV[1]
puts "\tPath: " + ARGV[2]
puts "\n"

begin
  http = Net::HTTP.new(website, port)
  resp, data = http.get(path, {'Accept-Encoding' => 'gzip, deflate'})

  encoding = resp.response['content-encoding']
  if encoding.nil?
    encoding = 'NO'
  end

  puts "\tCompression: "+ encoding + ",\t" + data.size.to_s + " bytes,\tmessage: "+ resp.message + ",\tcode: " + resp.code
  puts "\n"
rescue Exception => detail
  puts "An error ocurred. Execution aborted."
  puts detail.message
end
Categories: ruby Tags:

Single Instance Applications

March 18, 2011 Leave a comment

Hello! Here ‘s a fairly simple example of how to create single instance Applications with LibUnique and Gtk +. I took the example in the documentation and changed it to demonstrate how to pass a parameter to the active instance.

How to compile:

gcc -o uniquesample uniquesample.c
  `pkg-config --cflags gtk+-2.0 unique-1.0 --libs gtk+-2.0 unique-1.0`

How to run it, first launch first instance:

# ./uniquesample

Then, launch the others:

# ./uniquesample "One App to rule them All"

Here’s the code:

#include gtk/gtk.h
#include unique/unique.h

static UniqueResponse
message_received_cb (UniqueApp *app,
                     UniqueCommand command,
                     UniqueMessageData *message,
                     guint time_,
                     gpointer user_data)
{
  UniqueResponse res;

  /* get text payload from the unique message data*/
  gchar *texto = unique_message_data_get_text (message);

  /* Get the label widget */
  GtkLabel *label = GTK_LABEL (user_data);

  switch (command)
  {
    case UNIQUE_ACTIVATE:
      {
        gtk_label_set_text (GTK_LABEL (label), texto);
        res = UNIQUE_RESPONSE_OK;
        break;
      }
    default:
      res = UNIQUE_RESPONSE_OK;
      break;
  }

  return res;
}

static gboolean
delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
{
  gtk_main_quit ();
}

int
main (int argc, char *argv[])
{
  gtk_init (&argc, &argv);

  /* Create the UniqueApp Instance */
  UniqueApp *app = unique_app_new ("home.myapp", NULL);

  /* check if there already is an instance running */
  if (unique_app_is_running (app))
  {
    if (argc > 1)
    {
      /* build a message with the first command line argument */
      UniqueMessageData *message = unique_message_data_new();
      unique_message_data_set_text (message, argv[1], -1);

      /* send the message, we don't care about the response */
      unique_app_send_message (app, UNIQUE_ACTIVATE, message);

      unique_message_data_free (message);
      g_object_unref (app);
    }
  }
  else
  {
    /* this is the first instance */
    GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    GtkWidget *label = gtk_label_new ("UNIQUE INSTANCE");

    /* Makes app "watch" a window.
     * Every watched window will receive startup notification changes automatically
     */
    unique_app_watch_window (app, GTK_WINDOW (window));

    /* connect to the signal so we can handle commands and responses
     * We are passing the label widget here as user data */
    g_signal_connect (G_OBJECT (app), "message-received",
                      G_CALLBACK (message_received_cb), label);

    g_signal_connect (G_OBJECT (window), "delete_event",
                      G_CALLBACK (delete_event_cb), NULL);

    gtk_widget_set_size_request (GTK_WIDGET (window), 300, 200);

    gtk_container_add (GTK_CONTAINER (window), label);
    gtk_widget_show_all(window);

    gtk_main ();

    g_object_unref (app);
  }

  return 0;
}
Categories: Gtk+, linux

Gtk+ 3.0 Client Side Theme

March 12, 2011 3 comments

How to override user’s theme or I want my app with green buttons.

#include 

static gboolean
delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
{
	gtk_main_quit();
}

int
main (int argc, char* argv[])
{
  gtk_init(&argc, &argv);

  GtkCssProvider *provider = gtk_css_provider_new ();

  gtk_css_provider_load_from_data (
    provider,
    "GtkButton {font: Monospace 10; background-color: rgba(0%, 76%, 0%, 0.6);}",
    -1, NULL);

  GdkDisplay *display = gdk_display_get_default ();
  GdkScreen *screen = gdk_display_get_default_screen (display);

  gtk_style_context_add_provider_for_screen (
    screen, GTK_STYLE_PROVIDER (provider),
    GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  g_object_unref (provider);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL);

  GtkWidget *button = gtk_button_new_with_label("GtkCssProvider load from data");
  gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (button));
  gtk_widget_show_all (GTK_WIDGET (window));

  gtk_main ();
  return 0;
}
Categories: Gtk+

ogg to mp3

March 10, 2011 Leave a comment

If you have a device in your home that does not reproduce ogg files. :(

#!/bin/sh

find . -name '* *' | sort | while read FILE
do
	NEWFILE=`echo ${FILE} | sed 's/ /_/g;'`
	mv "${FILE}" "${NEWFILE}"
done

for file in *.ogg
do
	ogg123 -d wav -f $file.wav $file
	lame -m s -V 0 $file.wav
	rm $file
	rm $file.wav
done

find . -name '*ogg.wav.mp3*' | sort | while read FILE
do
	NEWFILE=`echo ${FILE} | sed 's/ogg.wav.mp3/mp3/g;'`
	mv "${FILE}" "${NEWFILE}"
done
Categories: Uncategorized

wma to mp3 shell script

March 10, 2011 Leave a comment

This shell script will convert wma files to variable rate mp3.

#!/bin/sh

find . -name '* *' | sort | while read FILE
do
    NEWFILE=`echo ${FILE} | sed 's/ /_/g;'`
    mv "${FILE}" "${NEWFILE}"
done

for file in *.wma
do
    mplayer $file -ao pcm
    mv audiodump.wav $file.wav
    lame -m s -V 0 $file.wav
    rm $file.wav
    rm $file
done

find . -name '*wma.wav.mp3*' | sort | while read FILE
do
    NEWFILE=`echo ${FILE} | sed 's/wma.wav.mp3/mp3/g;'`
    mv "${FILE}" "${NEWFILE}"
done
Categories: linux, shell script

Install VMWare-Workstation 7.1 in XUbuntu 10.10

February 24, 2011 Leave a comment

missing modules on your x86_64 system?
open a xfce4-terminal:

# sudo ./VMware-Workstation-Full-7.1.1-282343.x86_64.bundle
# cd /tmp
# wget http://www.sputnick-area.net/scripts/vmware7.1.1-patch-kernel-2.6.35.bash
# chmod +x vmware7.1.1-patch-kernel-2.6.35.bash
# sudo ./vmware7.1.1-patch-kernel-2.6.35.bash
# sudo vmware-modconfig –console –install-all

run vmware.

Categories: Uncategorized

Recover Grub2 Bootloader in XUbuntu

February 17, 2011 Leave a comment

1. Boot with Xubuntu Live CD
2. In a xfce4-terminal:

Create a mount point
# sudo mkdir /media/xubuntu

Mount your root partition somewhere, my root partition is sda2
# sudo mount /dev/sda2 /media/xubuntu

Mount proc and dev
# sudo mount -t proc none /media/xubuntu/proc
# sudo mount -o bind /dev /media/xubuntu/dev

chroot to your system
# sudo chroot /media/xubuntu

Re-install grub2
# grub-install

Done! reboot and enjoy.

Categories: Uncategorized

Ubuntu start up script for Mongo DB Server

October 25, 2010 4 comments

Very basic start up script for Mongo DB Server.
copy the file to /etc/init.d, set the execution flag, and run update-rc.d script_name defaults

#!/bin/sh

### BEGIN INIT INFO
# Provides:     mongodb
# Required-Sart:
# Required-Stop:
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description: mongodb
# Description: mongo db server
### END INIT INFO

. /lib/lsb/init-functions

PROGRAM=/usr/bin/mongod
MONGOPID=`ps -ef | grep 'mongod' | grep -v grep | awk '{print $2}'`

test -x $PROGRAM || exit 0

case "$1" in
  start)
     log_begin_msg "Starting MongoDB server"
     /usr/bin/mongod --fork --quiet --dbpath /data/db --logpath /var/log/mongodb.log
     log_end_msg 0
     ;;
  stop)
     log_begin_msg "Stopping MongoDB server"
     if [ ! -z "$MONGOPID" ]; then
	kill -15 $MONGOPID
     fi
     log_end_msg 0
     ;;
  status)
     ;;
  *)
     log_success_msg "Usage: /etc/init.d/mongodb {start|stop|status}"
     exit 1
esac

exit 0
Categories: linux, mongo

Replace Machine Name with Domain name in WCF Service wsdl link.

September 14, 2010 Leave a comment

If you installed your WCF service on a machine that has more than one network interfaces (internal and externals) then you probably faced to this problem: the wsdl link on your web services points to the internal domain (computer’s name) of the server hosting the services.

So, how to fix this? With the service metadata’s attribute, httpGetUrl.

End Point definition:

<service behaviorConfiguration="My.Service.Behavior" name="My.Services.API">
<endpoint address="http://my.externaldomain.com/serviceapi.svc" binding="basic" name="BasicHttpEndpoint" contract="My.Service.IServiceAPI">
</endpoint>
</service>

Behaviour definition:

<behavior name="My.Service.Behavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://my.externaldomain.com/serviceapi.svc/basic" />
</behavior>

Done, Now we have domain rather machine’s name.
If you need SSL, then go with httpsGetEnabled and httpsGetUrl.

Categories: Uncategorized

Tabu 2.2 Released

September 14, 2010 5 comments

Only source code available by now. This release is fully sponsored by the contributions of Valère Monseu, who added internationalization support. Enjoy!

tabu-audio-player_2.2

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.