Category Archives: Tech

Sending A PUT request to the Server using Ruby on Rails

I have been trying for ages to find out how to send a PUT request to the server using ruby on rails. This page makes no fucking mention of a put() function. I cursed on many occasion.  Here it is. Hope this helps someone.

require ‘net/http’
url  = ‘/api/user.xml?id=6’
post_data = “<user><firstname>Freeman</firstname></user>”
http = Net::HTTP.new(‘www.asdf.com’)
http.read_timeout = 300 # seconds
http.open_timeout = 180 # seconds
resp, data = http.put(url, post_data)

Math Captcha?

I am not sure what’s going on. My confusion comes from two things that as far as I know are correct. The 1st one captchas exist so we can tell if the user is human or machine. The second is that computers are good at doing calculations. I am right? Right?

So, if I am right… why is this a good idea?

Captcha

I am right? Right? What am I missing here… I could eval that with js easily to get an answer… and I’ve seen this captcha in more than one place.

I don’t know maybe there is some hidden technique I am missing. I would like to hear from you if you can explain.

Edit: The other version of this is asking in words something like “What is five plus two?”… have you ever typed that into google…? Google is a machine and it knows. Seriously, what’s going on here?

Silicon Cape Launch (as seen from twitter)

It starts of with Vinny Lingham’s talk and everyone complaining about how we need money to do what we want. We need VC to this we need VC to do that blah blah…. You don’t just get VC. You will get your VC if you have a good product.

The other feeling I got was that there were too many higher ups just talking and not enough ground level. Get your head out of the clouds (no, not decentralised infrastructure). It’s not the big guys that are important it’s the little guys with the big ideas. It’s the small guys that are the ones who are able to adapt to quickly market fluctuations not the big guys.

Then some props were going to Helen Zille for saying some inspring stuff and a little bit of circle jerking… not much though.. which is good.

Then ending off with people saying it’s an awesome conference and one or two tweets saying government needs to do something…. Are you serious? After all that you are still expecting hand outs from Government? Fuck government, don’t expect them or anyone to do anything for you. You need to be prepared to go it alone if you need to. If something happens, great! Otherwise, you need to make it happen yourself.

I really do hope the enthusiasm continues… Change the world. It’s up to you.

Plug and play code

I am a PHP programmer. Quite a seasoned developer if I say so myself. I have a background in computer science and have been doing commercial programming for almost 5 years now. So I have learnt a lot about programming and programming for the web. One of the things I love in an application is clean data. So that means trying to make sure no garbage data gets into your database. To do there are a lot of things you can do.

One example of this is email validation. On the surface email validation a simple task. Take the email address your user has typed in, apply some tests to it and make sure it’s valid. One of the ways to do this is with regular expressions. As with any data filtering or data filtering task, you can do something basic or you can try to cater for all cases. To give you an example of the complexity of email filtering, lets break down the parts of an email address. An email address consists of 3 parts: the user name, the @ symbol and the domain name. Simple enough. But to what extent do you want to make sure it’s clean? The most basic option is to check that it has those parts in the correct order. A level up from that is to do the previous check and then check that the user name contains only valid email address characters. From that you could also check that that the domain name is made up of two or more part separated by a dot. A step up from that is to do the previous three checks and check that domain has a valid domain extension. One up from that is to do all previous checks and then also check that the domain actually exists and resolves. This is all I am aware of but there might be additional checks you can do.

So anyways for simplicity sake lets just say you want to check the format is correct, the user name has valid characters and the domain name is made up of two or more parts. All of this could be achieved with a regular expression.

If you use PHP as I do, you could easily find a bit of code for this on the internet, hundreds maybe thousands of different iterations of code all claiming to do the same thing: Validate an email address.

The only problem is, I don’t trust source code found on individual’s pages on the web. I don’t know that user’s credentials. I don’t know what he knows, I don’t know what sources he used to build that code. Or if he used sources at all. And because it’s something that is seemingly so simple, it’s easy to not do it correctly. Unless it is a trusted library or comes from a person who I know to be of a specific standard, I won’t use that code. Otherwise, I want to be able to see the references used so that if it comes to it I can check that it claims to do what it says it does. If those references are there my test need to be even more rigorous than I would need for trusted components, meaning that I might as well have written it myself.

I noticed myself doing this the other day. Just a little tech… sigh… Tired of writing now. Guess I won’t be doing what little spell /  sanity check I usually do.

Philosophy of correk thinking

I started a site called correk thinking. You can find it in the links on the right. The site displays a single message for 24 hours. At 12 o’clock each night, a new message is displayed. That’s it. That’s the whole site, just a single message on a single page. I attempt to make the message a positive one.

This site really resonates with me. I started the site hoping that someday someone will happen to come across it, and hopefully on that day the site will be displaying the message that this person needs to hear. Hopefully it will give them the push needed for them to improve their life. It might not happen, it might never happen. I know that what I am hoping for is pure coincidental. You may think I am being silly but I had an experience where this exact thing happened to me. I had been thinking and introspecting on a problem for almost a month. And if I had not been in the exact place at the exact time, I may never have found the answer. And because I knew that finding the solution was pure chance, it really enforced the solution. So, what I am hoping to achieve is improbable but not impossible. I think the idea of it unlikely makes it even more appealing to me.

The site embodies a so much of what I believe in:

Done things for the sake of doing them. One thing I really love about the site is that if it does help someone, there’s an equal chance that I’ll never know that I’ve helped anyone. The site provides no contact details and no way to contact the owner/author. Due to the anonymity of the site (from both my side and the user’s side), it means helping people just for the sake of helping people, nothing else, no thanks, no recognition, nothing.

Secondly, positive thinking. At the core of the site, it provides a positive thought a day. I believe they way you think and talk to yourself in your head, determines a large part of your success (whatever success may mean to you). Also an added benefit, because I am trying to think of positive thoughts for the site it forces me to think positively at least once a day.

Thirdly, another philosophy I live by and also incorporated into the site is the Buddhist philosophy of the impermanence of all things. Nothing lasts forever. So every message is shown once and never again.

And fourthly, it’s just a little bit a day, just one line of text. This is my newest philosophy that I have adopted and it has made me a much happier person. For a large part of my life I wanted to be exceptional (hidden under the guise of appearing normal) but I wanted to be exceptional immediately. I wanted results now. This latest philosophy I adopted has taught me patience. Just a little a day.

And that’s it. http://correkthinking.com