Categories
PC Nerding

Counting Plastic Beads, now with a GUI

After making a command line version, I decided to make a GUI one. Not that there was a need to, but I was trying out Eto.Forms GUI library and this was a great excuse to try different features.
The program is single classed (two actually, but the first class only job is to run Main and create the second class), 140 lines, no cool programming or any great pattern example, it gets the job done and that what counts here.

Launch the application, click **load** to select your image and click **count** to get a list of colors (Hex format) and how many bead are needed per color.
Note: the counting includes background beads, if the same color is used for both background and front colors, you may want to edit the image in your favorite editor and change background color.

Should work on both .NET and Mono on all main desktop OSes (Win, OSX, Linux).

Download here: Beadscount GUI (2289 downloads ) (all platforms in the same zip, you can run the .exe using .NET or MONO or use run .app on OSX)
Source: on github.

Here’s a couple screens:
beadscount0

beadscount1

Categories
Gaming PC Nerding

Over tinkered voice chat for my 3DS

Almost one month ago Monster Hunter 4 came out, delivering the killing blow to my dying social life. Now, being the asshole I am, I have almost no friends and none of those have a 3DS to play videogames with me. But here comes the Internet, where you don’t need many friends to be happy and, thanks to a forum, I got some people to hunt with me on MH4. The problem is: 3DS has no voicechat and I love voicechatting with other players. We got around this limitation using a VPS and installing a Mumble server, but you need another device for using it, like a PC or a smartphone. And then you can’t use headphones on both your pc and 3DS, fuck it.
Easy solution? Use a stereo mixer or something like that, but I didn’t want to waste 25€, I had to improvise using what I had readily available.
So my solution was using an USB audio card, an Asus Xonar U3 that was lying around since the laptop it was connected to broke, plug both microphone and headphones in that card and use my PC’s line-in (set to loop) to get audio from the 3DS.

mh4_voicechat

This setup has the added benefit of listening to music in my headphone while playing.
The only downside was that in this case “size matters”: the only 3,5mm audio cable I had for 3DS-PC connection is extremely short and I have to keep my hands on the desk. I tried switching mic and 3DS output ports but for some reason the mic stopped working if plugged to my PC’s line-in and 3DS to USB audio had a noticeable hissing.
It might be a bit overkill for this use but hey, I was able to make it for free and if it’s stupid and it works, it’s not stupid at all!

Categories
PC Nerding

The cheapest JS URL shortener ever

After my previous article about shortening urls using htaccess, today I’m posting a little JS snippet that will allow to shorten urls, using a JSON array to store shorter and longer urls. The script will look in url parameters for a short url and redirect to the associated longer url. Have a look:

<!-- // Function declaration
function shorturl_redirect() {
	// This JSON array contains all the shorturl/url pairs
	var urls =[	{ "shorturl":"?lndm" , "redirect":"http://www.lanoiadimuu.it" },
			{ "shorturl":"?example" , "redirect":"http://www.example.com" },
			{ "shorturl":"?twitter" , "redirect":"http://twitter.com/lanoiadimuu" },
	// Get the url parameter
	var shorturl = location.search;
	// If there's no url parameter stop script execution
	if(!shorturl || 0 === shorturl.length) { return; }
	// Now the function will look though urls array and if a valid shorturl is found it will redirect the browser to the longer url
	for(i = 0; i < urls.length; i++) {
		if(shorturl == urls[i].shorturl) {
			window.location.replace(urls[i].redirect)
			break;
		}
	 }
}
// Function call
shorturl_redirect();
// -->

Now for an example, if you point your links to www.yourexample.com/?lndm or www.yourexample.com/index.html?lndm the script redirect your browser to this site homepage.

Some quick notes:
- It will work on any hosting/subdirectory/webpage/cms/browser combination, unless the visitor is actively blocking JavaScript (eg. NoScript plugin on Firefox). All php cms still need to be fully loaded by the hosting environment before serving the script.
- I suggest placing this snippet (or .js file) between head tags, ideally you want the browser to stop loading html and go to the provided link.
- You can wrap the code into a JS anonymous function, since the code needs to be executed only once.
- The script is really small in size: the above example is only 834 bytes including comments. Byte size will vary according to your array size and url lenghts, for example I made an array with 50 entries and it was 5,3kb.
- It does not require additional libraries, eg. jQuery, or additional url shortening services, eg. Bit.ly or Yourls.
- Depending on the behavior you may want, you could change window.location.replace with window.location.href . For more information read here.