BEEPS AND BLIPS FROM OUTERSPACE
HOW TO COMPILE MONGOOSE HTTP SERVER ON MINGW

The open source project Mongoose is a tiny HTTP server written in C.  I wanted to try it out using a free compiler on my Windows box, g++ on mingw, and had to resort to this hack to get it compiled:

  1. Use git to clone the project from github
  2. Copy the example hello.c in examples to the parent directory
  3. Apply the patch below to mongoose.c
  4. Then build:  g++ mongoose.c hello.c -lpthread -lwsock32

The patch (apply with patch -p0 < file.patch):

diff --git mongoose.c mongoose.c
index 47cd9be..c324136 100644
--- mongoose.c
+++ mongoose.c
@@ -108,8 +108,10 @@ typedef long off_t;
 #define strtoll(x, y, z) _atoi64(x)
 #else
 #define __func__  __FUNCTION__
-#define strtoull(x, y, z) _strtoui64(x, y, z)
-#define strtoll(x, y, z) _strtoi64(x, y, z)
+//#define strtoull(x, y, z) _strtoui64(x, y, z)
+//#define strtoll(x, y, z) _strtoi64(x, y, z)
+#define strtoull(x, y, z) (unsigned __int64) _atoi64(x)
+#define strtoll(x, y, z) _atoi64(x)
 #endif // _MSC_VER
 
 #define ERRNO   GetLastError()
@@ -1630,7 +1632,7 @@ static int alloc_vprintf2(char **buf, const char *fmt, va_list ap) {
   *buf = NULL;
   while (len == -1) {
     if (*buf) free(*buf);
-    *buf = malloc(size *= 4);
+    *buf = (char*)malloc(size *= 4);
     if (!*buf) break;
     va_copy(ap_copy, ap);
     len = vsnprintf(*buf, size, fmt, ap_copy);
@@ -4596,7 +4598,7 @@ static int set_ports_option(struct mg_context *ctx) {
                // On Windows, SO_REUSEADDR is recommended only for
                // broadcast UDP sockets
                setsockopt(so.sock, SOL_SOCKET, SO_REUSEADDR,
-                          (void *) &on, sizeof(on)) != 0 ||
+                          (char *) (&on), sizeof(on)) != 0 ||
 #if defined(USE_IPV6)
                (so.lsa.sa.sa_family == AF_INET6 &&
                 setsockopt(so.sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *) &off,
@@ -5209,8 +5211,8 @@ static int set_sock_timeout(SOCKET sock, int milliseconds) {
   t.tv_sec = milliseconds / 1000;
   t.tv_usec = (milliseconds * 1000) % 1000000;
 #endif
-  return setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *) &t, sizeof(t)) ||
-    setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *) &t, sizeof(t));
+  return setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &t, sizeof(t)) ||
+    setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *) &t, sizeof(t));
 }
 
 static void accept_new_connection(const struct socket *listener,
@@ -5238,7 +5240,7 @@ static void accept_new_connection(const struct socket *listener,
     // keep-alive, next keep-alive handshake will figure out that the client
     // is down and will close the server end.
     // Thanks to Igor Klopov who suggested the patch.
-    setsockopt(so.sock, SOL_SOCKET, SO_KEEPALIVE, (void *) &on, sizeof(on));
+    setsockopt(so.sock, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on));
     set_sock_timeout(so.sock, atoi(ctx->config[REQUEST_TIMEOUT]));
     produce_socket(ctx, &so);
   }
POSTED 2013-08-14 03:17:48 CATEGORY SOFTWARE TAGS MINGW
HOW TO OBFUSCATE AND PACKAGE A LIBGDX APP FOR DISTRIBUTION

First off: This is an Impatient Guide and it will be short on explanation and possibly accuracy

Second off: This method is a first attempt and is probably fraught with errors and inefficiencies, but it worked for me.

Let's get started!

Say you have a LibGDX project and you want to package it up for redistribution, but you don't want to give out a jar and would like it to be wrapped in a nice executable (.exe) just like any ordinary Windows binary.  In addition, obfuscating the code to make reverse engineering more difficult might be something you want too.

Here's how I did it manually with Eclipse, ProGuard, Launch4j, and 7-zip.

Creating the JAR files:

  1. Export a jar file with the Eclipse Export Wizard.  I did this for my desktop version, by right clicking on the project "myapp-desktop" -> Export -> Java -> Runnable Jar File.
  2. Plug in the usual stuff into the wizard, but choose "Copy required libraries into a sub-folder next to the generated JAR."  Otherwise, ProGuard will make your life a nightmare when you try to obfuscate (e.g. "Warning: org.lwjgl.input.Controllers: can't find referenced class net.java.games.input.ControllerEnvironment").
  3. Hit "finish" and the wizard will generate your shiny new .jar file.
  4. Do 1 through 3 again, but in step 2 choose "Package required libraries into generated JAR."  The jarinjarloader files and the MANIFEST.MF from this second generated JAR will be used later on.

Obfuscate your jar with ProGuard:

  1. Run the GUI version of ProGuardjava -jar proguardgui.jar
  2. In the Input/Output tab, click "Add input..." and enter the first generated JAR path.
  3. Click "Add output..." and enter your output JAR... say (e.g. output.jar).
  4. Click "Add..." in the Add libraries section and add the library export directory generated with the first JAR.  If your export JAR name was foo.jar, the export dependencies should be in foo_lib.
  5. In the Obfuscation tab uncheck "Use mixed-case class names."
  6. Keep the default settings for now (you can tweak them later once you have this working).
  7. Start processing the JAR.  In the Process tab click Process!
  8. If ProGuard finishes it will produce a nice obfuscated/shrunk JAR, output.jar.

Combine library dependencies into obfuscated JAR

  1. The output.jar is not runnable as is.  It needs to know how to find the library dependencies.  You can pack the dependencies into the JAR with 7-zip.  So, open output.jar in 7-zip.
  2. Add/drag the contents of foo_lib (from step 2 in the first section) into the root level of the JAR (e.g. they should be in the same directory META-INF is in).
  3. Extract the other JAR from the first section (see step 4) into a temp directory (e.g. temp).
  4. In output.jar, clobber the file "META-INF/MANIFEST.MF" with the file from "temp/META-INF/MANIFEST.MF".
  5. In output.jar, add the directory "org/eclipse" from "temp/org/eclipse".
  6. Confirm the JAR is runnable: java -jar output.jar

Wrap your JAR in a Windows executable

  1. Use Launch4j to wrap your JAR.  Open the Launch4j GUI.
  2. Add your output file: out.exe
  3. Add your input JAR file: output.jar
  4. In the JRE tab, set the Min JRE version (e.g. 1.6.0)
  5. Click the gear icon to build the wrapper.
  6. Confirm the binary works.  High Fives all Around!
 
POSTED 2012-07-07 22:05:59 CATEGORY ENGINEERING SOFTWARE TAGS DEVELOPMENT JAVA LAUNCH4J LIBGDX JAR PROGUARD IMPATIENT GUIDE
NGINX: HAVE STATIC AND PHP FILES PLAY NICE TOGETHER

While trying to configure Nginx and PHP so that the PHP files would run from the same directory as static files, the error "290 rewrite or internal redirection cycle while internally redirecting to "/index.php"..." persistently recurred.

Everything worked fine after changing nginx.conf to the following (inside server {):

root html;
index  index.php index.html index.htm;
location / {
  try_files      $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
  include fastcgi_params;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  fastcgi_pass   127.0.0.1:9123;
}

Source (in the "Also Good Section")

POSTED 2012-06-30 17:00:00 CATEGORY ENGINEERING SOFTWARE TAGS NGINX PHP CONF
HOW TO SEND URL PARAMETERS IN BACKBONE.JS

Say you want to request a collection from the server in backbone.js, but don't want to receive every single item available.  Instead, you want to receive only the first 100 items.  Well, jQuery.ajax options can be passed directly as fetch options. docs

So, when you want to fetch the collection call the following:

instance_of_your_collection.fetch({data: {count: 100}});

If there are problems with the above, try parameterizing the data:

instance_of_your_collection.fetch({data: $.param({count: 100})});

On the server side, if you are using the Slim Framework with PHP, you can check the parameters like so:

$app->request()->params('count');

 

POSTED 2012-06-29 00:00:37 CATEGORY SOFTWARE TAGS JQUERY BACKBONEJS SLIM PHP
HOW TO RUN PHP ON NGINX WITH SLIM FRAMEWORK ON WINDOWS

I found myself wanting to test some PHP on my local Windows machine and wanted a lightweight, fast solution besides Apache.  My motivation was getting a test environment with a RESTful serverside api for backbone.js testing.

The resulting toolchain is comprised of:

  1. Nginx (a tiny, fast HTTP server)
  2. PHP
  3. Slim Framework (framework for writing RESTful APIs and applications)

Being no fan of PHP, getting this configuration was like putting salt on a wound, but it might be useful for those that want to get up and running in a very short time.  I'll keep the explanations to a minimum to stay true to an Impatient Guide.

  • Download and unzip nginx to c:\nginx-xxx\ 
  • Download and unzip PHP to c:\nginx-xxx\php\ 
  • Open c:\nginx-xxx\conf\nginx.config in a text editor and uncomment the .php (FastCGI) location config to look like this (take note of the bold items):
location ~ \.php$ {
  root           scripts;
  fastcgi_pass   127.0.0.1:9123;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  include        fastcgi_params;
  try_files      $uri $uri/ /index.php?$args;
}
  • Download RunHiddenConsole.exe to c:\nginx-xxx\php\ 
  • Create a batch file called start-php-fcgi.bat in c:\nginx-xxx\ with the following (take note of the bold items):
@ECHO OFF
ECHO Starting PHP FastCGI...
set PATH=C:\nginx-xxx\php;%PATH%
RunHiddenConsole.exe C:\nginx-xxx\php\php-cgi.exe -b 127.0.0.1:9123
  • Your PHP files will be put in a directory called scripts so download the Slim Framework into c:\nginx-xxx\scripts\ 
  • Start nginx and FastCGI via a console window:
> cd c:\nginx-xxx\
> start nginx.exe
> start-php-fcgi.bat
> curl.exe -i -X DELETE localhost/index.php/delete
HTTP/1.1 200 OK
Server: nginx/1.2.1
Date: Tue, 26 Jun 2012 00:35:50 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.4.4

This is a DELETE route
  • That's it.  You're done.  High Five!!

One neat thing about this toolchain is you can zip everything up and make it portable.  There is no need to mess with installers, environment variables, etc...

Confused?  Visit PHPFastCGIOnWindows.

POSTED 2012-06-26 20:34:53 CATEGORY ENGINEERING SOFTWARE TAGS DEVELOPMENT WINDOWS SLIM NGINX IMPATIENT GUIDE PHP
FILESTACK - A SIMPLE OPEN SOURCE BLOGGING PLATFORM

After one hack to many, I've decided to abandon my WordPress installation on Dreamhost and create my own lightweight replacement.  WordPress is just too large a target for hackers and comment spammers making a small blog a chore to maintain and backup.

Thus, Filestack was born.  It's an open source, Apache 2.0 licensed, blog platform built on Django.

Here's it's raison d'être:

  • Easy content storage with files (back up is painless)
  • Single user
  • Basic CMS features: Scheduled publishing, Categories, Tags, etc...
  • WYSIWYG HTML editor
  • No destructive actions, like content deletion, available via HTTP
  • Quick serving of a WordPress export file

Bonus Features:

  • Themeable and with Django templates
  • File upload helper
  • Encapsulated Django app with quick installation

Filestack was built with Python, Django, jQuery, 960.gs, fancybox, and TinyMCE.

You can find the source code on GitHub.

Screenshots:

You are looking at it.  8BitRobot.com is running Filestack with the default Newsprint theme.

POSTED 2012-06-06 18:26:56 CATEGORY SOFTWARE TAGS JQUERY 960GS FANCYBOX WEB PYTHON TINYMCE DJANGO BLOG WORDPRESS OPENSOURCE
HOWTO: SORT A SQLITE STRING COLUMN AS AN INTEGER
information icon There are times where you have to work with a data set that isn't typed correctly.  Say you have a sqlite database where one column is a number but in a string type:
sqlite> CREATE TABLE stuff (description text, inventory text);
sqlite> SELECT * FROM stuff;
forks|4
spoons|401
knives|12
Now, say you need to sort the data based on the integer in a string type (inventory above).  Here's how you would do it:
sqlite> select cast(inventory as number) as inv, description from stuff order by inv desc;
The output will be:
401|spoons
12|knives
4|forks
see the spec.
POSTED 2012-03-28 15:16:29 CATEGORY SOFTWARE TAGS DATABASE INTEGER SORT SQL SQLITE STRING
HOWTO: DOWNLOAD A YOUTUBE VIDEO ONLY USING YOUR BROWSER
download flash youtube linkSo you want to save a YouTube video?  You've probably used a search engine and found tools like KeepVid, Keep-Tube, and a plethora of browser extensions for Chome and Firefox.You probably thought twice  about using those tools because adding an extension to your browser or running a Java Applet inside it can be a security risk.  It makes you wonder why you can't simply obtain a link to the flash file to download.  It's saved (cached) on your computer when you watch a video anyway...Well, you can get a link to the flash file (.flv) on a YouTube video without needing anything but your browser if you are using Chrome.  If you are using Firefox, you can use the FireBug developer tool extension.Here's how you do it.  I'll keep it short and sweet, but keep in mind the method is similar for both Chrome and Firefox.Overview: Use developer tools to see which files are being sent from the server, identify the video flash file, then obtain a link to it.Steps to obtain a Flash link to a YouTube video:
  1. Open your browser.
  2. Open the appropriate developer tools (Chrome: CTRL+SHIFT+I,  Firefox*: F12).
  3. Click on the Network or Net tab.
  4. May need to enable Network Monitoring (obvious if you see an explanation in the Net tab).
  5. Navigate to the YouTube video.
  6. When the video loads monitor the file list and find the one that is the flash file.  On Chrome, the type will be "video/x-flv" and named something like videoplayback.  On Firefox, it can be named the same "GET videoplayback?....", but you will need to click on the file to see the type, "video/x-flv."  If you have trouble, just look for the file that has a long transfer time... the one that continuously transfers (See the image below).
  7. Right click on the file and choose either "Copy link address" or "Copy location."
  8. Now you have the link.  However, before you can use it, make sure you close the original YouTube video webpage.  YouTube has smart caching logic so that only one of your connections will be active at one time.
  9. You now have two choices:
    1. Paste your link into your browser (after closing the previous playing video), then doing a "Save As" to save it to your computer.  This will download the video a second time, which is why I recommend...
    2. Create a link, right clicking it, and choosing "Save link as..."  How do you do this?  Use this tool to create an HTML Link for you.

getting youtube video flash link with chrome developer tools

Now you can get a link to the flash video on YouTube with only your browser.  Expect a later post on how to convert a flash video into another format like mpeg.
POSTED 2012-03-26 11:35:13 CATEGORY DIY MOVIE SOFTWARE TAGS DEVELOPER DOWNLOAD FLASH FLV HOWTO LINK TOOL YOUTUBE
JS1K: SPEECH SYNTHISIZER IN 1KB OF JAVASCRIPT
JavaScriptAs part of JS1k#4, Mathieu 'P01' Henri threw together a speech synthesizer with 1KB (actually 1020 chars) of Javascript.It isn't easy to understand, even if you already know what the synthesizer will say, but it is impressive Mathieu created it with under 1KB of code.JS1K is very similar to the game development cram event ludumdare.see other entries at JS1K.
POSTED 2012-03-18 11:43:05 CATEGORY NEAT SOFTWARE TAGS JAVASCRIPT JS1K
TOTAL CONFUSION
Total Confusion - utility to determine how a total was made with simple numbersI got a wild bill from PG&E a month ago that required them to check gas meter readings.  They determined they were at fault, but the resulting bill after corrections was absurdly confusing.  There was no easy way to figure out how they reached the total amount with the numbers they were providing.  Charges, fees, and payments were not clearly stated.So, I threw together a web application utility tool that takes the total and all the numbers that might possibly be used to calculate a total, and spit out which values were added and which were subtracted to equal the total.It was fun and easy to write.  It is also useful.  So, I've put it on the interweb so you folks can use it too.The calculation tool is aptly named: Total Confusion
POSTED 2012-03-16 11:36:28 CATEGORY ENGINEERING SOFTWARE TAGS ADD CALCULATOR IF A UTILITY HAS NO COMPETITION IT SHOULD BE STATE CONTROLLED PGE SUBTRACT TOTAL UTILITY WHY ARE ALL UTILITES EXTREMELY HASSLING
prev page
• • •
next page