ReubenLi.NET

[R] Plotting a decomposition by STL using ggplot

Wasn't too satisfied with the default stl plot available using plot and the process of making a normal vector a ts object so I wrote a script to do so:

decomp <- function(series,frequency){
  na.stinterp(series)  -> x   #this is for interpolation
  ts(x,start=01,freq=frequency) -> x1 #converting into a ts object
  stl(x1,s.window="periodic") -> x2 #performing stl on the ts object
  data.frame(x,x2$time.series) -> x3 #creating a data.frame
  index(x3) -> x3$index #create an id
  colnames(x3)[1] <- "time-series" 
  melt(x3,id.vars="index") -> x4   #melt the dataframe into long format 
  ggplot(x4,aes(index,value,group=variable)) + geom_line(alpha=0.7) + facet_grid(variable ~., scales="free")  + xlab("Timesteps") + ylab("values")
}


Android app flow

package space.works.customicon;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class CustomIconActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

protected void onStart(){
super.onStart();
Toast.makeText(getApplicationContext(),"Start",
Toast.LENGTH_SHORT).show();
}

protected void onRestart(){
super.onRestart();
Toast.makeText(getApplicationContext(),"ReStart",
Toast.LENGTH_SHORT).show();
}

protected void onResume(){
super.onResume();
Toast.makeText(getApplicationContext(),"reSume",
Toast.LENGTH_SHORT).show();
}

protected void onPause(){
super.onPause();
Toast.makeText(getApplicationContext(),"pause",
Toast.LENGTH_SHORT).show();
}

protected void onStop(){
super.onStop();
Toast.makeText(getApplicationContext(),"Stop",
Toast.LENGTH_SHORT).show();
}

protected void onDestroy(){
super.onDestroy();
Toast.makeText(getApplicationContext(),"Destroy",
Toast.LENGTH_SHORT).show();
}

}

 

Evernote (hacks?)

Started using Evernote and I think its a pretty nifty software/app. Though one of my main gripes is the fact that security is solely dependent on Evernote's server which is out of my control. Nevertheless, I'm using it for less 'confidential' tasks. I've been playing around and have seen some shortcomings which I have attempted to 'fix'. Here is the list:

1. No Linux clients

Well, officially at least. One possible workaround is to simply use the web-client. For me, however, I've opted to use NixNote (formerly NeverNote) which is an open-source clone that allows syncing with the EverNote server. 

Apart from its rather plain design. It packs certain functions not found in the original EverNote client such as highlighting in the editor. 

2. No Highlighting Ability

As mentioned above, this is possible using NixNote. Alternatively, you could edit the html file in the app client with highlight tags (too tedious probably). I've noticed that the Android app for EverNote stores the notes as html files in the local directory (unlike the Windows and NixNote clients which store the notes in a database file).

3. Syncing using own cloud server

I have not tested this but I suspect it may be possible to do so purely by syncing the db file across different desktop clients. Create local (not synced) notes to prevent them from being synced with EverNote's servers and sync these files across your clients using your own cloud solution such as OwnCloud. 

Passing Variables using GET Method to Bash CGI Script

It is not often that one uses a linux shell CGI script as there are more popular alternatives such as Perl. However, for shell programmers like me, it seems so much more... parsimonious, particularly for simple tasks or simply to use AWK, SED, etc...

One difficulty I had with a shell CGI script was the passing of variables using the GET method. It is a wee bit more straightforward in Perl. Below is one possible solution:

Ingredients

URL command

This could be a HTML form such as:

<FORM action="/cgi-bin/crossword.cgi" method="GET">
Clue: <input name="formvar1">  <br>
Pattern: <input name="formvar2">
<input type="submit" value="Submit">
</FORM>

Or something that generates and runs a URL command such as http://www.reubenli.net/cgi-bin/crossword.cgi?find=cut&patt=%3F%3F%3F%3F

Shell Script 

Create a shellscript and place it in your cgi-bin directory. Don't forget to give it 755 permissions (chmod 755).

Include the straightforward heading lines including the shebang and the Content-type if you desire a return: 

#!/bin/bash
echo "Content-type: text/html"
echo ""

And here is the highlight:

for assigning GET variable to bash variable, if there is only a single variable:

eval $QUERY_STRING

for multiple variables:

var1=`echo "$QUERY_STRING" | sed -n 's/^.*formvar1=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` 
var2=`echo "$QUERY_STRING" | sed -n 's/^.*formvar2=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`

Note that those are backticks.

Run

Now if you used the form method, just point your browser to the form, fill it up and hit enter or submit. You should be getting your desired result page. Similarly, you could just enter the URL command in any browser and get the same return.

Replacing Yen (¥) key with backslash key (\)

Till date I haven't found a way to do this in ubuntu after switching to japanese display. However, I realised that despite looking different, both symbols work in the same way on the command line, e.g. yen as an escape.

Subcategories

App - Camera Disabler/Locker

My Very First Android Application! This is a very simple app designed to enable users to disable the camera for whatever reasons they may have. 

 

OwnCloud

My very own cloud network is up! Lemme know if you want an account to play with. This cloud syncs my server in Tokyo, my machines at home and a laptop that I carry around with me.

 

App - Cracked Screen Prank HD

This is my most downloaded android app (among the 2 published -_-"). Its almost reaching a 1000 downloads!

 

Android Developer

Elastic Layout!

Try resizing the browser window and see how this webpage reacts! Read more about responsive web design here.

Member Area

Contact Me