Home Server May 2017
Tuesday, May 02, 2017

It has been no secret that I've been working on a few personal projects of my own. My friends know how fucking excited I've been getting lately when I hit my milestones.

Since I've been repeating myself a lot lately and it's quite hard to explain quickly without the aid of diagrams, I created some diagrams.

Firstly, I'm using an open source solution called Docker for hosting my services and it's amazing and I urge you devs out there to check it out. In simple terms, it's a way of virtualizing services rather than the OS itself. The benefits are that there is less overhead, starting and stopping services are just a few simple commands away and you can duplicate as many services as you want across a cluster(swarm).

Right now I have a few services that are always turned on.

  1. Automated torrent downloading
  2. Google Drive-like service for files
  3. Internal DNS service
  4. Service manager for docker containers
  5. VPN service

I also have some development sites that runs on and off based on changing needs (eg. web, database service).

Secondly, I've been reading up quite a lot about reverse proxy and I've been wanting to set them up for months/years(?!) but just haven't had the time to get to them. In simple terms, a reverse proxy is kind of like a seamless way of redirecting users to the correct server based on the URL. It could be used for load balancing, or in my case, used as a transparent way for end users to access the services*.
* | why not DNS? Because DNS only resolves IP but cannot resolve port numbers. My services are only exposed by port and are (mostly) on a single machine so I had to do it this way.

However, I still have a DNS service running because I need to be able to resolve URLs to a physical machine. (no messing with host files anymore)

An overview of how it works is shown in the diagram below.


--- update ---
Made a mistake in the diagram, when accessing data.service it goes directly to the DNS service then to the NAS. Does not require nginx to resolve at all.

When the reverse proxy server (aka. nginx) is hit with a URL query, eg. (http://torrent.service), it looks in the configuration where to redirect the user to seamlessly in the background. The seamlessness/transparency is a very powerful tool. I will explain it in more detail after illustrating how the general flow of logic of this setup.


* | client machine must be configured to use my DNS server (forced over VPN)

When user visits any site ending with .service or .dev, the DNS service will return the address of the services. Because most of the services are hosted on one physical machine, the nginx (reverse proxy) service resolves the incoming request to the corresponding service/dev.
* | if user visits another site eg. google.com, it will be resolved normally to the internet (albeit with a very slight latency overhead)

Going back to why nginx (reverse proxy) is a powerful tool, it's really the transparency that makes it awesome. When the user visits http://torrent.service, the DNS resolves it to the machine (eg. 172.16.1.66:80*). The nginx service listening on port 80 takes that query and forward it to the service (eg. 172.16.1.50:12345). However, to the end user, the URL never changes, the visible IP never changes, it all works seamlessly in the background.
* | IP and port number separated by semi-colon

eg. You navigate to the "downloads" page. The visible URL changes to http://torrent.service/downloads, it looks like it's 172.16.1.66:80/downloads to the system, but it's actually 172.16.1.50:12345/downloads. It all takes place automagically.

It's great when everything comes together but I definitely had my fair share of problems when setting it up and have to combine multiple sources of answers online before I could get my services running the way that I want them to. There is still 2 amazing projects that I'm looking to tackle before school starts proper, my fingers are crossed.

I'll like to clarify that when I say service, it may be made up of one or more services. For example http://torrent.service is made up of Transmission (the downloader service), and Flexget (the background service that searches for latest episode).

To end it off, everything is hosted either on my secondhand Thinkpad X200 (released in 2008), or on a Raspberry Pi 3. So if there's anyone who's interested in sponsoring me for anything (I can even make a video about it), contact me.

Labels: , , ,


Text Expanders: aText for Mac
Tuesday, August 16, 2016

Despite having a pretty fast typing speed (~120 wpm), I'm always looking for ways to improve the speed of how to get the ideas from my head onto the screen as fast and efficient as possible.
text expanders are awesome

Enter text expanders. It allows me to use self-defined keywords to expand whatever text I choose. A simple example would be

brb : be right back

The moment I type those letters, it will auto expand out into it's full glory. Of course you can use triggers like [tab] to prevent expansion when you don't intend it to, but for my own use I find that instant expansion fits my needs; YMMV.

The app I use for my MacOS is called aText.
I can add any thing I wish and it'll just expand out, the common uses are for things like your email, names and such. I haven't been making full use of it yet as I only started dabbling with it near the end of my school term, but with it starting soon I'm sure I'll add many new snippets to it.

Following the trend of the previous productivity post, I created a GIF to show how it works.


As you can see I can quickly generate blank templates for whatever language I'm currently coding in. I've used it for awhile and it saved me a lot of keystrokes. It also allows me to quick insert time and date in whatever format I prefer, saves me the effort of checking and typing when needed.

There are quite a few competing software for MacOS but I think aText has the best value for the function it delivers without being too complicated. As for Windows, I've only used Phrase Express and it works same way. However I find that it feels a bit clunkier, not slow per say but it doesn't feel as instant.

Which is experience I get when switching between a Mac and my Windows desktop machine, when I want to modify a behaviour that ties in deeply with the system, MacOS always does it better (probably due to it's unix nature).

Oh as a bonus there's this emoji expander you can use natively with your MacOS without extra software. It allows you to do Slack type of emoticon usage.
https://github.com/warpling/Macmoji
I have it and it's pretty cool! (even though I almost never use it)
But for those people who can't live without emoticons 😢 😕 😄 , this is a really simple way to use them without spending too much time. Here's a GIF from the author that shows how it works.


Hope this helps in your productivity! The next post is probably a thought post WOT style. Stay tuned.

Labels: , ,


Alfred 2 Add To Temp workflow
Monday, August 15, 2016

As someone who surfs the net every single day, there will be times where I find something interesting and want to note it down. It usually comes in the form of a link. There are many apps out there that allows you to jot down random notes really quickly, but it still requires some mouse clicks or quite a few key strokes.

Simple note taking shortcut.
With the help of Alfred* as a digital assistant, I can create small scripts that reduce the amount of actions required. I'm using the paid (powerpack) version in case you're curious.
*only for MacOS

The scripts are called "workflows" in Alfred, it's a relatively simple IFTTT (if this then that) kind of idea.
It follows the pattern of [keyword/trigger] > [action] > [result/output]

As you can see, it's really simple, and it's relatively easy to make your custom workflows too as long as you know a bit of bash, or python, etc.

"att" is just a keyword that I chose (add to temp) for appending any of my note to this temporary file; while "temp" is a keyword for opening/viewing the saved snippets. Words aren't as effective as a simple gif, so here.

Native notification to show appended text!

As you can see, it allows your snippet to be of any length, even multiline paragraphs works as expected. It is also tagged with Date/Time to make searching a little bit easier. On the topic of searching, I may add that feature to this workflow so that I can search through the notes from Alfred itself, though I'm pretty sure that the "find" function in Sublime Text will beat any kind of search algorithm I can come up with.

With this, I can add any note within 4 actions.
Copy text, open prompt, att, paste
Since I don't have a place to host the .workflow file, let me just share with you the secret sauce that makes all of this works. It's just a 1 line bash command. Formatting the date, time, then passing in the {argument} that Alfred receives then appending it all into a text file. That's it!

printf "$(date +%d-%m-%y) | $(date +%r)\n{query}\n\n" >> ~/Documents/scripts/temp.txt

Well, hope you guys like this little cheat that I've shared. I still haven't test it out in school yet but it has proven rather effective in normal use. Next post shall be on the text expander that I use to reduce the amount of repetitive typing I have to do, stay tuned!

Labels: , ,


POP lo!
Friday, October 18, 2013

After 4 months of grueling training, I have finally graduated from BMT.

Alright because there's really just too many things that has happened over the past few weeks so I'm going to consolidate everything in kind of a half-assed manner. But yeah, there's still the stupid field camp to write about. But anyway, first and foremost, I have finally left that island!





The rest of the pictures are already on FB so... yeah can't be bothered to post them all. But my bro really did take quite a few good shots, not bad.



So in the previous post I wrote about signing on Army.

Well, that didn't happen.

To more be precise, I was rejected for that vocation. You must think that the army must be crazy for turning me down, and yeah they are; but there are a ton of reasons why it didn't go through. The thing is that this was always a win-win situation for me. It doesn't matter if I didn't enter because it just means that I will only have 2 years to serve instead of 5.

Oh, yeah by the way I got posted as an Auto Tech. Which means that I will be repairing vehicles. It's... rather interesting to me. I have always been interested in vehicles and this is just a chance for me to actually get my hands on them.

Well, it's actually really lucky that I got this. I don't think that I will have to run about; I think. Either way, seems like the next 2 years of my life has been settled, there's not much to say about it until I go next Monday.

Read more »

Labels: , , , , , , , , ,


Desktop April
Saturday, April 13, 2013

Running Windows 8

It has been a really long time (years maybe) since I've bothered customizing my desktop, because I want it to perform as quickly as it can and didn't want to waste valuable resources beautifying it. However, I noticed that I have a surplus of computing power so I decided to make use of it.

But I still didn't want to tweak the system files for maximum stability, so all I did was change the icons on the taskbar and used Rainmeter for the clock and system monitor (bottom right).

The desktop icons are hidden using Stardock's Fences. Double click to show or hide the icons, which eliminates unnecessary clutter.

Anyway you see that little arrow on the bottom left?

Start menu FTW

Yeah, it's a friggin' start menu on Win8. I'm using a program called StartisBack. And I actually paid for it. I got a bundle so I could give 3 licenses out for free if any of my friends asks. Though I don't usually like to pay for little programs like these, I think it's worth it for the low price and the functionality that it brings.

Alternatively, you could use Classic Shell to emulate the experience but it's just not as clean speaking from my own experience.

I don't know if it's because I'm a power user or anything, but I really can't stand the "Modern UI", especially when I'm actually trying to get some work done.

Example of Win8 default start screen

That UI makes no sense on a desktop environment. If not for the slew of improvements under the hood, I would've stuck with Windows 7. As many have said, Windows 7 is the new Windows XP. It just works, and it works the way you expect it to.

Oh well, I have tweaked my Win8 to work like Win7 as much as possible, and so far everything is awesome. The minimalist approach towards my desktop simply satisfies the my OCD. Speaking of which, I really cannot stand it when people have cluttered desktop or unorganized folders.

I need new hard drives. And on that bombshell it's time to end.

Labels: , , ,


Cleaning my mechanical keyboard
Friday, March 29, 2013

CM Storm Quickfire TK with 80% keys removed

Bought this baby about 3 months ago, and I have been using it rather extensively everyday since. If you know one thing or two about keyboards, it's that it is dirty. How dirty is it exactly? It's dirtier than your toilet. [source 1, source 2, source 3, source 4]
*to be fair, a toilet is actually really really clean. It's built to be anti-germ and anti-bacterial after all.

So it's the first time since I got this that I'm going to clean it extensively. This of course, requires taking out all the keys as you can see.


Just in case, I aligned all of them correctly when I took it out, better safe than sorry.

I think my skills of taking pictures/blogging has dropped. I should've taken a picture of the ring I use to remove the keys, I should've taken a picture of the keyboard with the dust and hair in it, but I didn't. So you have to put up with the following paragraph.

The keys comes out fairly easily, there's a little plastic thingy that you jam into the keys and just pluck them out. Now for the disgusting part, most of your keyboard's junk comes from your hair. It may seem mild until you see strands and strands of hair stuck in the weirdest positions, interlocking each other. It's something you have to see for yourself to understand, just clean your keyboard, you ought to. 
(random thought: the one time being bald is beneficial)

Went out today to get this bottle of compressed air. You won't guess how expensive this bottle of air is.


It's fifteen fucking bucks, spelt with an F.

I don't know how they manage to persuade me to buy a bottle of nothingness for $15, but they got me good, real good.

Alright enough jokes, it's more expensive than it needs to be but it's not as cheap as you might think. It's not totally compressed air inside, there's a liquid that evaporates to generate the pressure needed, then the bottle will get cold Result, it works far longer than just a bottle of air.

Anyway, as you can tell I get a little OCD about my hardware. I was going to clean my desktop at the same time but I just couldn't find the vacuum cleaner for whatever reasons. However, all these little quirks doesn't exist without a reason. It's not that I must have a keyboard in pristine condition*, but for something that I'm going to put my hands on for a prolong period of time, I think this amount of cleanliness is appropriate.
*my Logitech Illuminate is still in good shape

Man, in retrospect, this seems like such a pointless thing to write about. Oh well, who cares.

Labels: , , ,


Geek: Adding 2 fans to my desktop
Saturday, March 09, 2013

Yeah, the bottom is messy, I can't help it

I realized that I perspire quite a bit when I'm doing things related to my desktop. I don't know why, maybe I'm nervous I'll break something, or I'm just too anxious to get it finished and done. (or maybe I'm tired)

This is why I didn't take a lot of glamour shots. I took some shots, but nothing note-worthy.
First things first, what did I get?

Noctua NF-B9 PWM Fan ($30)


CoolerMaster Blade Master XtraFlo Slim 120 ($18)
Purely for pushing air into the case


Powered PWM 1-4 splitter cable ($12)

Reasons for getting a premium Noctua fan? Because sadly, I'm running a rather small cooler that uses a 92mm fan, there wasn't anything in the shop that is optimized for pressure at that size except this, so... yeah.

I almost forgot to write about this, but I'm using 2 fans for my CPU heatsink (Cooler Master Hyper TX3 EVO). This is known as a push-pull configuration. So 1 fan is sucking in air, and the other is pushing the air out. Do I really have to go this far? Not particularly, but a lower operating temperature increases the longevity of your electronic components. More about this later.

I had to shift the locations of the fans around due to constraints, but here's how the front fan looks like.


I think and hope that my case is neater than those normal computers. I tried to keep the cables as tidy as I could, for the sake of good airflow. However, as this is counted as a budget case, there wasn't a lot of room for me to do cable routing.

Here's how it looks like at the back.

It was really hard closing the case like this.


A peek inside the case! 
After putting everything back together, here's how it looks like from the showcase side.


Taking a closer look...

How are the temperatures like? I ran a program called Prime95 that will stress test your CPU. It does prime number calculations, which will put your CPU at 100% load. (using Core i7 3770)

First run
Idle temperatures: 39°C
Load temperatures: 69°C

I'm getting stable temperatures of 69 degrees celsius. Which is an amazing improvement of over 10°C. I used to get numbers of the low 80s. This has been going great so far, but there was a problem.

The sound. The sound of the fan is distinctively clear. I am not a huge fan of a desktop that makes noise. So I opened up the case once again, added some pads to dampen the sound, added a cable that reduces the fan speed. It became audibly better. I could still hear it, but it's a slight annoyance I'm willing to put up with. Sadly, I do not have a sound meter, but I'm pretty sure it's around 36dBm and above. Definitely going to do something about it in the future.

After tweaking here and there, maybe I somehow managed to get the correct amount of airflow in and out of the case, the numbers looked even better.

Second run
Idle temperatures: 39°C
Load temperatures: 62°C

A 7°C difference is huge. Especially in an air-cooled solution. Considering that the room temperature was around 32°C, the delta for idle temp is only 7°C, and the load temp delta was only 30°C. Not the most amazing cooling I have seen, but it's good enough for me to live with, considering that the delta for load temp was around 50°C before the upgrade.

I am very pleased with the results. With summer fast approaching, and ridiculously warm weather these days, this is just a type of precaution.


p.s. I'm a little anal about the noise. I should definitely get it checked out ASAP.

Labels: , , , , , , ,


Geek Rant: My head is full
Wednesday, March 06, 2013

I haven't written much about my own life ever since exams started, and ended last week. Sure, I might have procrastinated almost every single day, but that'll depend on how you define procrastination!

I am pushing in as much information as I possibly could, regarding computers of course. I have learnt the syntax and basics of Python (programming language), there are a ton of tutorials online. Going to get further into it when I feel like I'm ready.

Installed a Windows 7 virtual machine in VMware and made it as barebones as possible. It only takes up 350MB RAM at boot up. Used to experiment applications in a sandboxed environment. (was testing Spoon.net, check it out!) Also using it to run jperf (GUI version of iperf). jperf is used to run a network load test, which I used to test my router's wireless throughput with my laptop. (it's working, but I haven't collect the data yet) Reason for doing this virtually is because Java is generally buggy, I refuse to install it on my main system.

Started to try running pre-built virtual machines, which are known as Virtual Appliances. Got a LAMP stack up and running pretty quickly, going to use it to try and do some sort of management interface for my home network.

Got started on a Wordpress server as well.



As you can tell from the address, it is hosted locally via a Virtual Machine.

It wasn't as hard as I thought it would be, and there are many great documentations about the Wordpress platform. I am a little tempted to try hosting my blog on my own server, hesitating as it entails leaving my computer on 24/7, which is something I didn't build it for.

However, I am considering doing a test run, then throwing it up to AWS (Amazon Web Services) to host my Wordpress server. Which comes at a monthly fee. Something I am not quite sure if I'm ready to commit to yet.

That said, my paranoia is working it's magic and I kinda feel like having a private blog, within my private network. So there's a 0% chance of anyone discovering it. I could even assign a proper URL to it that only my home network could access, the possibilities are endless.

Unfortunately, that's all I had time for so far. There's still a personal email server I want to try hosting, and an online collaboration platform. Virtualization is just splendid!

I say that this is "procrastination" because well, I really do need to find a job to fund my interests. Having such a powerful CPU is a wonderful head start, but it never hurts to have more and better hardware, does it?

Man, my head is so full now.

Labels: , , , , , , ,


Talk: Unix Chat program
Tuesday, February 19, 2013


Chat and communication is an interesting topic, and a challenging problem back in the 80s when computers first entered the consumer market.

There wasn't such thing as inter-system operability. In short, if you were using a Mac, there is no way you can talk to another person on Windows. (since the internet/email wasn't really there yet) Alright this is a bad example, let me write a short summary of what it's like back then.

You have something called a mainframe, or workstation. Computers are really expensive then, so multiple users would share 1 computer. (imagine multiple users logged into your computer and using it at the same time, but not directly affecting each other) Each user has a screen that connects to the computer, and they could execute commands to it. Of course, the computation powered is shared among the number of users. And the wonderful Operating System is called Unix. 
(Windows/Mac OS are created afterwards for user-friendliness)

During the era that doesn't have internet, how would you chat with another user on the same computer?
Introducing, Talk.
(such a creative name)

Read more »

Labels: , , , , , , ,


LOG: Step 1 of world domination
Sunday, February 03, 2013


After years of mindless wandering, I've finally decided to put my skills to the test. Everything that I've learnt will be used in order to make this work.

I am going to create a web portal that allows me to access and control every aspect of my home network, from the scratch. Sure, I could always use a corporate solution, or even using home server solutions. But where's the fun in that?

There are 5 main functions that I'm interested in for the moment.
LOGS: Display logs from selected devices. (routers mainly, SNMP)
COMPUTERS: Manage my computers. Remotely boot up/shutdown, remote desktop and ssh access
ROUTERS: Well... just the management page for it
FILES: Access files from any device. (mainly the NAS)
BACKUPS: Scheduled backups to NAS. Summary/management

Draft of what it might look like

Sure, I could simply use Windows Home Server to do most of the stuffs I'm going to do. Why not do that?

For one, I must have a decently powerful computer turned on at all times. That sucks up electricity and is probably idle most of the time, terrible for efficiency. Whereas I could host this web portal on my router, which takes up maybe 4 Watts or less of electricity.

Trying to implement proper security all of these will also be an interesting problem to tackle.

Again, the question people always ask me is
"Why?"
It's a little hard to explain when it comes to computers. Think of it this way, people train very hard to play instruments properly. They learn some tough pieces to challenge themselves, or maybe because they love that piece. Or that people in sports train their body to perfection, because they want to be better at it, that it's challenging.

This is a challenge to myself. It may not seem intuitive to many people, but that's how I view my interactions with computers. I love what I can do with it, and I want to get better at it. For the years of learning I haven't really had anything substantial to show for myself. Sure, a couple of neat tricks here and there, but nothing as big as this.

Let's see how much I have progressed over the years, shan't we?

Labels: , , , , , ,


Geek: SSH Tunneling fun
Wednesday, January 30, 2013

I have a home VPN set up at home. Which is obviously the elegant, and secure way of connecting to my home network.

I'm pretty sure I mentioned about SSH tunneling sometime ago, how it's considered as a "poor man's VPN". What it does is simply create an SSH connection, then tell my computer "Hey, here's a secure connection, please throw whatever packets you have at it."

The end result is something similar to a SOCKS5 proxy, which is technically what it is.

What I experimented today in school is doing VNC over SSH, which technically isn't very difficult if you're on Linux, but it's a little more hairy on Windows. Thankfully there are already tons of guides out there so it really isn't that hard.

However, as it's still under the advanced section, I shall draw a diagram, to help myself understand.


The BLUE refers to my SSH connection to 1 of my routers. Here, I could have set up a tunnel that I could push my web traffic through. (a single port)
The GREEN is the interesting part. I am using the blue connection to tell the router, "Hey, I need to talk to that computer at home, set up a link between a port on my home computer, and a port on my laptop." (but the router doesn't know it's doing that)
The ORANGE refers to the actual path of the traffic.

I would point to the defined port on my locahost, and it will be redirected to my computer at home as it is "linked". However, my green connection is still encapsulated within my blue connection. So it's kind of like a tunnel within a tunnel.

And with that, I would've finish setting up a VNC connection to my home computer through a SSH tunnel. I tried it with FTP but I screwed something up and kept getting request time-outs. I'll fix it tomorrow though.

Yes, there is a practical application. I did a test run on my FYP project using this link in school. The end.

Labels: , , , , , ,


Review: CM Storm QuickFire TK - Cherry MX Blue
Saturday, January 26, 2013

My first mechanical keyboard

This is more of my experience with this keyboard than a detailed specification of what this keyboard can do. You can find that detail anywhere online.

I got my hands on this bad boy roughly 20 days ago, as a present to myself.

I got the Cherry MX Blue switches mainly due to the tactile feeling you get. There are 4 main types of Cherry MX switches* on the market. Red, Blue, Brown and Black. Blues have the most tactile feeling to it, brown is tactile, similar to blues but quieter. Reds are linear, not much of a tactile response, Blacks are similar to red but quieter.
*the brand of keyboard switch used

I'm just going to put this out there first. A mechanical keyboard definitely enhances your computing experience.


Read more »

Labels: , , , , , , ,



Java: GUI basics
Tuesday, January 22, 2013

Turns out I'm pretty good at this Java thing, there's a test on this Friday and I don't particularly want my friends to fail so here's something for you guys to read. If you managed to understand everything, you will pass with flying colours without a doubt.

The files that I'm using can be downloaded here. I'm using the Shops.java file mostly for this. Follow this post carefully, if there are sections of code that seems alien, don't worry, they are probably not tested and are written as a challenge for me.

I'm basing this tutorial on Practical 8 Part 2 GUI.



First off, the Layout Manager.
In order to use it, you need to import the necessary libraries, in this case it's
import java.awt.*;
Which has to be declared at the very beginning.

public class Shops extends JFrame implements ActionListener {

private JButton Shop1 = new JButton("Shop1");
private JButton Shop2 = new JButton("Shop2");
private JButton Shop3 = new JButton("Shop3");
private JButton Shop4 = new JButton("Shop4");
private JButton shopcart = new JButton("Shopping Cart");
private JButton quit = new JButton("Quit");

public Shops() {
this.setLayout(new BorderLayout());

JPanel panelA = new JPanel();
this.add(panelA, BorderLayout.CENTER);
panelA.setLayout(new GridLayout(2,2));
panelA.add(Shop1);

panelA.add(Shop2);
panelA.add(Shop3);
panelA.add(Shop4);

JPanel panelQ = new JPanel();
this.add(panelQ, BorderLayout.SOUTH);
panelQ.setLayout(new GridLayout(1,2));
panelQ.add(shopcart);
panelQ.add(quit);


The first line declares that Shops is a child member of JFrame, and implements the Interface called ActionListener. This allows you to use methods and functions from JFrame and ActionListener.

JButton is declared to create a Button.
JLabel is declared to create a Label that you can assign text to.
JTextField is declared to create 1 Text Line you can write to.
JTextArea is declared to create multiple Text lines you can write to.

public Shops() is a constructor for the class Shops. You have to write this or you wouldn't be able to construct the object.

this.setLayout sets the LayoutManager used for the Frame you're creating. So far we've only learned BorderLayout and GridLayout.

this was a pain to draw

Assuming a GridLayout(2,2), it'll create a layout on the left.
Using a BorderLayout will look like the one on the right. Yes, the space distribution is that weird.

A panel is a space you use to enter your content.
JPanel panelA = new JPanel();this.add(panelA, BorderLayout.CENTER);panelA.setLayout(new GridLayout(2,2));
panelA.add(Shop1);
Creating a panel is really straight forward as you can see. You can then use the name of your panel to add items into it.

Now, the most important piece of code to look out for.

//library to import import java.awt.event.*;
Shop1.addActionListener(this); Shop2.addActionListener(this); Shop3.addActionListener(this); Shop4.addActionListener(this); shopcart.addActionListener(this); quit.addActionListener(this);

You must put this in. This tells the program to listen/watch out for your Shop1 button. So that it will know if you press it or something. (if you're confused where all these goes, refer to the downloaded files)

public void actionPerformed(ActionEvent e) { 
// TODO Auto-generated method stub 
if(e.getSource()==Shop1) { 
item1 = 1.00; 
item2 = 2.00; 
item3 = 3.00; 
Shopping shop1Form = new Shopping(total[0], tempno1, 1); 
shop1Form.setTitle("Shop 1"); 
}
else if(e.getSource()==Shop2) { 
item1 = 3.00; 
item2 = 4.00; 
item3 = 5.00; 
Shopping shop2Form = new Shopping(total[1], tempno2, 2); 
shop2Form.setTitle("Shop 2"); 
}

This section of code is where the magic happens. This is the method implemented by the ActionListener. Remember, when you implement an Interface, your class must have all the methods of the Interface. (which can be imported when you hover over you class that has a red underline, then add unimplemented methods, like this)

Look at e.getSource()

e is simply any variable you assign to the ActionEvent. It could even be (ActionEvent Fuck), in which case your code would be
if(Fuck.getSource()==Shop1)
That means that if you click on Shop1, something will happen, whatever code that you put to it. Then I simply create another Object from the class Shopping, passed some variables and voilà, a new window pops up like this.



The idea is the same for the other Classes that I've created.

Okay, the class is all good and done, how do you actually make it come out?
You write a test program to calls upon the object. Refer to TestGUI.java

Shops newShop = new Shops(); newShop.setVisible(true); newShop.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); newShop.setTitle("Shops"); newShop.setSize(400,350); newShop.setLocationRelativeTo(null);

Here, I'm creating a new Object from the class Shops, with the name of newShop. You have to setVisible to true, or you can't see it, obviously.

setSize determines the size of the frame.
setLocationRelativeTo determines where the window will pop up. null will center the application.

Remember that you have to create the Shops object in a main method, which in something like this

public static void main(String[] args) { }

You need a main method for the program to run after all. The other classes are pretty much constructed in the same way that I've explained so far.

Finally, catching error exceptions. The code works like this

try { 
some function you're working on 
} 
catch(some kind of error) { 
what to display if this error happens 
} 
catch(another kind of error) { 
display something else for another kind of error 
} 
finally { 
do something at the end of everything 
}

This is rather straight forward. Really, just read up on Chapter 9 and I promise you will understand it. Think of it as an if-else statement that captures certain errors. I do not remember the types of errors, but I'm sure it'll be provided in the test.


And this is pretty much it.
If there's a large chunk of stuffs that I didn't cover, that's because I implemented a cache system for each object. That is why I could store the quantity of items, along with the total cost of each shop.

Again, this is something you could understand as I merely used all the things that has been taught from Chapter 1 to 9. As long as you understand 90% of my code, you can score 100 for the test. I swear.

I took my precious time to write this. If anyone of you read this and still failed, I will personally shove my fist up your butthole. Be warned.

Labels: , , , , , , , ,



Geek rant: I forgot how being non-geek felt
Tuesday, January 15, 2013

If you've known me long enough, you'll know that it has been years since I walked down the path of geekhood. And because I have been pretty much learning and reading everyday, I totally forgot how it's like to be a normal person.

My friend asked me (paraphrased) how to set up a wifi access point on a laptop so that her phone could use the school's internet. (the laptop is connected via wire). Shamefully, the first though that came into my head was: "You don't know how to do that?!"

Regretfully, this is the same reaction I always have when people ask me a question related to tech. I swear that I'm not trying to be pretentious or anything, I really do think that it's something someone should know.

Think of it as learning how to cycle. Once you've learnt it, it's really hard to imagine not being able to do it.

Which is actually a feeling that I really miss. It's not like I'm that good in anything, but I, or anyone for this matter, wouldn't be able to just revert to how your skill level was before learning something; and I do enjoy learning, that sense of achievement when you understand or are able to accomplish something you never could before.

So sometimes, I do wish that I will forget how to do some of these geek stuffs and re-experience that joy of making things work again.

Labels: , , ,


Geek rant: Network level up!
Sunday, December 16, 2012



After 2~3 days of continuous tinkering with my network and computer. I have final-fuckingly create a setup where I can access anything from the internet. Here are the services that I've set up for myself.


  1. Music streaming server
  2. (S)FTP File server
  3. HTTP File server
  4. SSH tunneling
  5. Home VPN


That's pretty much all the connectivity that I need for the moment. There is still VM streaming through browser and other more technical things that I haven't quite figure out yet. If you remember me being frustrated about my home network, I've fixed that as well, I can finally pass through all traffic to and from the internet without any problems.

So, all those services, what are they and what can I do with it?

Read more »

Labels: , , , , , ,


Geek: Edna music server
Friday, December 14, 2012

Pardon my rambling as I am very annoyed but there isn't anyone who can listen or understand my frustration. Ever since I've gotten my hands on such powerful hardware, it's only natural that I try to put it into good use.

So far I have 3 VMs created nicely with direct connection to my network. I'm currently using Ubuntu to setup my stuffs before I try to increase performance on a light weight server. Setup-ed 2 factor SSH authentication with no problem, it's very interesting to see it work actually.

Currently, I'm trying to work on a Music Server, which allows me to stream my music to any corner of the house. I'm using Edna music server at the moment, which is a really small and lightweight program that streams music over HTTP using a m3u playlist. Sadly, I can't seem to find a way to make it work on my phone. Other computers are able to play it without a hiccup.

Of course, this could be expanded to allow me to stream my music over the internet. Which is when I hit the same fucking brick wall I did the last time round. My home network. It's pretty complicated for a small network. Because of that, my file sharing network is not exposed to the internet, which is a good and bad thing. I tried forwarding the traffic along but it just doesn't seem to work. I've tried all that I've been taught, but to no avail.

That's when I realize that I'm going to have to fix this network before I can continue experimenting on my little projects.

Alright, something to do with the title. Edna is rather flexible, and with a little tinkering here and there, you could share your libraries with your friends. (Though there are better music servers for that) I was thinking that if I could set everything up perfectly, I could ask some "willing" friends to set up their own servers and we could access each other's music collection over the net. It's very cool and definitely something worth spending some time on. Though I highly doubt there'll be anyone who is willing to crack their heads for this. Oh well, there'll be more interesting posts once I figure everything out.

Labels:


Geek: New desktop
Sunday, December 09, 2012

Honestly, I thought the post will be a lot more interesting than this, but it turns out that I was so eager to build the system that I couldn't be bothered to take the pictures. So..... instead I'll just be rambling on how amazing this is.

Intel Core i7 3770
Intel HD Graphics 4000
ASUS P8B75-V Motherboard
120GB OCZ Vertex 3 (old)
2TB Seagate HDD
8GB of RAM
Cooler Master TX3 CPU Cooler
Thermaltake Commander MS-I Case
520W Modular PSU

Yep, it's just the barebones of a system, good enough to make it work. But with a really really fast CPU in it.


I'm currently running a W7 on VMware with 1.5GB memory assigned to it, which explains the high memory usage. And, I'm not using Windows 8 now because there hasn't been a permanent "hack" for it yet.

Cold boot takes less than 20 seconds. Everything is as snappy as it can be. Though I haven't been utilizing its full potential yet. The whole build took me almost 2hours to assemble. Mostly spent on cable management, trying to make the case neat and tidy, which is kind of pointless since I put it behind a monitor and it can't really be seen anyway.


Read more »

Labels: , , , , , , , ,


Geek: Web Design
Thursday, December 06, 2012


This may be a bit of a surprise but I'm actually on version 7 of this template! Of course, they have mostly been small tweaks apart from the change in logo.

I started with about 350 lines of code and I'm currently almost at 570 lines. It may be pointless but well, I have taken interest in it again, so it's kind of a hobby for me right now. I used to design my own templates couple years ago, until I got bored of it. Mainly due to the complexity of coding required to achieve fancy looks and transitions.

However, thanks to the arrival of CSS 3.0 and HTML 5, all the crazy scripting has mostly disappeared. And are welcomed by the concise CSS codes instead. I am rather proud to say that everything here is still done using only code! Because I'm still new to this new era, I had to do a lot, and I do mean, a lot of searching And I would love to point out the improvements made, not going by versions.

Read more »

Labels: , , , , , , , ,