Cookie and Cookie Jars with REST API

Been playing with ERPNext a bit recently. Tried to test the REST API so as to learn how it works.

In the Frappe documentation, it says to login like this:

snapshot1

Tried the following code in my terminal and it worked

$ curl --data "usr=Administrator&pwd=admin" http://localhost:8000/api/method/login

However the API to test whether the user has been logged in was not working

$ curl http://localhost:8000/api/method/frappe.auth.get_logged_user

It would NOT work :-/

If i would paste the URL in my web browser, it would recognize that i was logged in.

I realized cookies are being used. To do it from the command line, all i had to do was create a cookie jar and later fetch the cookie from the jar 😉

$ curl --data "usr=Administrator&pwd=admin" http://localhost:8000/api/method/login --cookie-jar lol

$ curl http://localhost:8000/api/method/frappe.auth.get_logged_user --cookie lol

It would finally recognize me now. 😀

Democracy

Democracy is marketed as the ability of the people to have power in their hands. But what is it actually?

Every 5 years, for 5 minutes, you have the right or power to put 3 crosses on a sheet of paper next to your favorite candidates.

5 Years contain approximately 2,592,000 minutes.

The rest of the 2591995 minutes, it is a dictatorship. Our hands get tied up. Our mouths gets taped. Sticks are put in our wheels. Literally.

Employees and students wait for the Prime Minister’s and the President’s car to go before to be able to reach their office and schools.

  • Did the people want the Mauritian beaches to be sold to hotels and restaurants?
  • Did the people want speed cameras? Or roads which are safe, fast and efficient?
  • Did the people want Rs 50 million crappy gov.mu website?
  • Did the people want frauds? If you’re a ‘petit copain’, then yes
  • Did the people want the Government to store their fingerprints and bio-metric photos?
  • Did the people want a Rs 2 billion prison facilities?
  • Did the people want to increase the bus fares when it was already high? 1,2

But now, something bigger is going to happen. We won’t even have that 5 mins. The current PM wants a permanent seat on power by planning to become President. The opposition joined the government. What do we have now?

Can we choose who we want to be our dictator? Or can we choose our supreme dictator?

Schedule Downloads at Night on Raspberry Pi

The best time to download heavy files is at night. Because during the day, you need the bandwidth to do your own work. A Raspberry Pi is ideal for downloading. It doesn’t consume lots of power. It can be plugged directly into your router’s USB port for power and Ethernet. You can also attach an external hard-drive to it.

CameraZOOM-20140905212531444

wget

$ sudo apt-get install wget

It is installed by default in Raspbian and lots of other Linux distros.

at

$ sudo apt-get install at

at allows you to schedule a command at certain time.

Let’s say we have to download Qt for Android 5.3.1 (Linux)

$ ssh pi@192.168.1.x
$ echo 'wget -c http://download.qt-project.org/official_releases/qt/5.3/5.3.1/qt-opensource-linux-x64-android-5.3.1.run' | at 02:00

The -c argument tells wget that if an existing download was in place, resume it 😉

Remember the Anil Bachoo Stupidity Fund?

He increased all bus fees by Rs 2 because of mismanagement/fraud in NTC and he didn’t want to investigate into the matter.

See how each time i paid the bus fees, the Anil Bachoo Stupidity Fund (ABSF) stands out.

Why give Rs 2 on top of Rs 25, Rs 100 and Rs 200 notes?
Because the conductor would eventually ask me if i got Rs 2 so that he/she could return me a Rs 5 or Rs 10 coin.

Rs 2 per travel. If you take 4 buses per day, it makes Rs 8. Anyways. Government bribe people. People will vote again…

Moisture Sensing with Raspberry Pi

I had bought a moisture sensor for quite a long time. But i didn’t have an Analog-to-Digital converter. I hence bought a MCP3008. But then, i didn’t have a breadboard and wires to connect my equipment. Today i finally managed to get everything and build it 😀

Moisture Sensing with Raspberry Pi

I followed the guide found here

However, i was having a problem by importing the mcp3008 module in the Python shell. It was giving me the following error

>>> import mcp3008
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mcp3008.py", line 4, in <module>
spi.open(0,1)
IOError: [Errno 2] No such file or directory

Googling a bit, i came across the solution here. All i had to do was to remove the black listed SPI modules in etc/modprobe.d/raspi-blacklist.conf

I tested my setup by dipping the moisture sensor in water. When not in water, I would get a value of 1023. When fully dipped in water, it would be floating from 450 to 470. To get the readings in terms of percentage, i used the following formula/code

while True:
m = mcp3008.readadc(5)
m = (1024 - m)/450.0 * 100
print 'Moisture Level: ' + str(m)
sleep(.5)

moisture_sensor

Wo wo wo! Wait! Why using Windows???

Long story! Infact, i’m using Putty on Windows 7, ssh’ed in a virtual Ubuntu Server in Virtual Box from which i shh’ed to my Raspberry Pi. To summarize: Windows 7 > Ubuntu Server (Virtual) > Raspberry Pi

Who do such a thing? Because Putty was not able to connect directly to the Raspberry Pi. My Git Bash also failed for dunno what reason. Had to use a virtual Linux as middleman. lol 😀

Neways, now i plan in getting a temperature and other sensors (pH maybe) in the mix too. 🙂