Archive
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:
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();
?>
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.
403.14 mvc
If you get the error 403.14 when opening a MVC based web application, then here are a few checks:
- Ensure that you have a web.config in both the root and Views folder
- Ensure that MVC 2 is installed on your webserver
- Run C:\Windows\Microsoft.NET\Framework64\v4.0.30128\aspnet_regiis -i
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.
GIF Proxy – Convert GIF to JPG (for Silverlight)
One of the most irritating features of Silverlight, is that it can’t handle GIF images. There is the Imagetools library from CodePlex, but it’s complex to implement.
Here’s a simple way of doing it, via a GIF proxy. This is a simple web page that takes a url of a GIF image in the querystring and outputs a JPEG:
Example: Here’s a GIF: http://www-wales.ch.cam.ac.uk/~wales/CCD/Thomson2/gif/560.gif
And Here’s it as a Jpeg: http://{removed}/GifProxy.aspx?url=http://www-wales.ch.cam.ac.uk/~wales/CCD/Thomson2/gif/560.gif
Great for Silverlight, WP7 (Windows Phone 7) etc.
CrossDomain.xml proxy
Ever tried to request a url in Silverlight, or WP7 to be stopped because you need to have a crossdomain.xml file installed in the root of the server.
Here’s a solution, a crossdomain.xml proxy.
Call http://<url>/CrossDomainProxy.aspx?url=http://YOURDOMAIN/YOURSCRIPT
and http://<url>/CrossDomain.xml is set to accept all hosts and requests.
Therefore even if there is not a CrossDomain.xml policy file on your server, you can use this proxy to bypass that.
Please, if you use this, give this blog a link back!, and a thank you would be nice!
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);
}
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)
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>
Free SQL server database
Here are connection details to a free 20MB SQL server 2008 database. It is public access, so don’t upload anything here that you need to keep, since somebody else can delete or change your data. However, this still can be useful for tests, or temporary applications.
Connection string
Connect with database management tool
Host: db003.appharbor.net
Username: db2625
Password: TJhwRAo75YrxcFUWVZWyoUqsFKkisiQafnrAmowLdph4usBnNsdsA4A8tXXgqfNU