Archive

Archive for the ‘Uncategorized’ Category

Open Source Pastebin in .NET

A pastebin is designed to be an easy way to quickly post some text online, so that others can see it. It also has applications in cross-firewall data traversal, where one peer can upload data to a pastebin, and the other peer can poll the pastebin for the message to arrive.  This was the kind of pastebin I was after.

I looked at pastebin.com and paste.kde.org, to see if they were suitable. Paste.kde.org seemed promising,  where you could paste easily, using a URL like this:

http://paste.kde.org/?paste_data=Hello+World&paste_lang=c&api_submit=true&mode=xml&paste_project=fiachspastebin

Which would return an ID, which you could retrieve using http://paste.kde.org/api/xml/117613, for example. The problem came, when I wanted to list all pastes by a particular user, or project, and I spotted that it wasn’t working as expected, like http://paste.kde.org/~fiachspastebin/api/xml/all/ seemed to return numerous pastes by other users.

So, I decided to write my own pastebin, which would store the messages in-memory. This meant that they would be deleted as the IIS worker process recycled, but, I didn’t need longevity.

Using two simple actions “action=update” which either created or updated a paste, and assigned it to a “user“, containing the text contained in the “text” querystring parameter. Then when “action=get” then the text associated with that “user” would be returned.

So, to store text with a user, you simply call:

http://url/pastebin.aspx?action=update&user=dananos&text=Hello+World

Then to retrieve that text you call

http://url/pastebin.aspx?action=get&user=dananos

And that’s it. The code I used is below:

  public static Hashtable data = new Hashtable();
    protected void Page_Load(object sender, EventArgs e)
    {
        string action = Request.QueryString["Action"];
        string user = Request.QueryString["User"];
        string text = Request.QueryString["Text"];
        if (string.IsNullOrEmpty(action) || string.IsNullOrEmpty(user))
        {
            Response.Write("Action and User is required");
            return;
        }
        if (action == "update")
        {
            PasteBin.data[user] = text;
            Response.Write("OK");
        }
        if (action == "get")
        {
            if (PasteBin.data.ContainsKey(user))
            {
                Response.Write(PasteBin.data[user]);
            }
            else
            {
                Response.Write("NO DATA");
            }
        }
    }

I’ve ported the same code to PHP, for Linux users. This code requires the $_APP library, which is posted at http://www.leosingleton.com/projects/code/phpapp/

This is hosted at http://pastebin.omadataobjects.com/bin.php

<?php
include("app.php");
application_start();
$action = $_REQUEST["action"];
$user = $_REQUEST["user"];
$text = $_REQUEST["text"];
if ($action == "" || $user == "")
{
   echo("action and user is required");
}
else
{
   if ($action=="update")
   {
	$_APP[$user] = $text;
	echo "OK";
   }
   if ($action=="get")
   {
	echo stripslashes($_APP[$user]);
   }
}
application_end();
?>
Categories: Uncategorized

Bluetooth on Android

I came accross the APK file for BlueTooth for android, Bluetooth_File_Transfer_4.20.apk, which if you rename to a ZIP you can decompress. You then can convert the resulting DEX file into a JAR using DEX2JAR. Then you can convert the JAR into Java classes using JD-GUI.

The resulting source code can be seen here: http://zip.webtropy.com/default.aspx/qeOS3a

Worth a look.

 

 

 

Categories: Uncategorized

403.14 mvc

Categories: Uncategorized

Free App Hub account, without Dreamspark

In order to get a Microsoft App Hub account, you can either pay 100 USD or, if you are a student, use a Dreamspark account to get in for free. If you neither want to pay the 100 dollars, and are no longer a student, then we can offer you a free account.

If you would like to publish an app on the Windows Phone 7 App hub without an account, then simply send us the XAP file, along with the required graphics and a description, and we will publish it on your behalf. Email us at support@openmerchantaccount.com with your app.

Graphics required are:
Application icon included in package (62×62 PNG)
Application tile image included in package (173×173 PNG)
Small tile (99×99 PNG)
Medium tile (173×173 PNG – normally this would be the application tile image)
Large tile (200×200 PNG)
Background artwork (1000×800 PNG – this is optional)
Description Text
Keywords Text
One or more application screenshots (480×800 PNG)

We do not offer outpayments, but your app will be published as a paid app. If you want your app to be published as a free app, then contact us for a price. Updates to apps will be charged at a reasonable rate.

During the approval process, if your app fails, then you will be given one attempt to fix it. If you fail a second time, then a small charge will be requested before we submit subsequent times. A PDF will be sent to you describing the fault.

Categories: Uncategorized

GIF Proxy – Convert GIF to JPG (for Silverlight)

Categories: Uncategorized

CrossDomain.xml proxy

Categories: Uncategorized

Find All Websites on a Webserver in C#

This is a handy script that can tell you how many sites are hosted on an IP address.  It uses  the Bing API, so it basically asks bing if it knows of sites on that IP address. This means that they have to be listed in bing, i.e. with public access.

 

 

 public static int SitesOnIP(string ip)
        {
            string url = "http://api.search.live.net/json.aspx?";
            url += "Appid=92B665B5421E197DC762503859279DFEBBE0B998";
            url += "&query=IP:" + ip;
            url += "&sources=web&web.count=50";
            // "Web":{"Total":31900
            string strRegex = @"Web....Total..(?<Count>\d+)";
            WebClient web = new WebClient();
            string strJson = web.DownloadString(url);
            string strCount = Regex.Match(strJson, strRegex).Groups["Count"].Value;
            return Convert.ToInt32(strCount);
        }
Categories: Uncategorized

A better XML to JSON proxy

I was looking for a generic way to convert XML to JSON, and I came across this GAE version http://jsonproxy.appspot.com/proxy, however, I noted that it only converted the first node of any tree to JSON, so it missed out most of the data contained in the XML.

Lets say,  we wanted to load exchange rates into a mobile app running Javascript (read phonegap /Wrtkit /Webos), an XML feed can be found at http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml (European central bank), but it’s easier to work with JSON than XML in Javascript. If you use the GAE (google app engine) version, then you only get USD, so I wanted to write my own proxy to fix this.

So, with the help of a free .NET Hosting account from brinkster Which worked an absolute charm – I didn’t have to put load on my own server to run this!. I installed my own XML-To-JSON Proxy:

I’ve fixed this, in a C# Implementation:

http://<url>/default.aspx?url=http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

vs

http://jsonproxy.appspot.com/proxy?url=http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

(obviously, you need to urlencode any querystring parameters after the URL in both cases)

Categories: Uncategorized

Using JSONP to show books from the Google API.

JSONP is one of the few technologies that allows cross-site scripting (XSS), whether this is by design or an oversight, here is an example of a Google Book Search using JSONP

<html>
  <head>
    <title>Books API Example</title>
  </head>
  <body>
    <div id="content"></div>
    <script>
      function handleResponse(response) {
	  html = "";
      for (var i = 0; i < response.items.length; i++) {
        var item = response.items[i];
        // in production code, item.text should have the HTML entities escaped.
		html += "<hr><img src=" + item.volumeInfo.imageLinks.thumbnail + ">";
		html += "<br>" + item.volumeInfo.title;
		html += "<br>Written by ";
		for(var author in item.volumeInfo.authors)
		{
			html+= item.volumeInfo.authors[author] + " ";
		}
		html += "<br>Published by " + item.volumeInfo.publisher;
		html += "<br>Published on " + item.volumeInfo.publishedDate;
		if (item.volumeInfo.pageCount != undefined)
		{
			html += "<br>Pages " + item.volumeInfo.pageCount;
		}
		for (var identifier in item.volumeInfo.industryIdentifiers)
		{
			var isbn = item.volumeInfo.industryIdentifiers[identifier];
			if (isbn.type=="ISBN_10")
			{
				html += "<br><a href=http://www.amazon.com/exec/obidos/ASIN/" + isbn.identifier+ "/httpnetwoprog-20>";
				html += "Buy at Amazon USA</a>";
				html += "<br><a href=http://www.amazon.co.uk/exec/obidos/ASIN/" + isbn.identifier+ "/wwwxamlnet-21>";
				html += "Buy at Amazon UK</a>";
			}
		}
	  }
	  document.getElementById("content").innerHTML = html;
    }
    </script>
    <script src="https://www.googleapis.com/books/v1/volumes?q=harry+potter&callback=handleResponse"></script>
  </body>
</html>

 

Categories: Uncategorized

Free SQL server database

Categories: Uncategorized