Wednesday, April 15, 2015
Deep male mysteries
Listen to Into the Deep Male Mysteries - Robert Bly Interview by bladesofgrass #np on #SoundCloud
https://soundcloud.com/bladesofgrass/into-the-deep-male-mysteries-robert-bly-interview
The white cow by Rumi
There is a small green island
where one white cow lives alone, a meadow of an island.
The cow grazes till nightfull, full and fat,
but during the night she panics
and grows thin as a single hair.
What shall I eat tomorrow? There is nothing left.
By dawn the grass has grown up again, waist-high.
The cow starts eating and by dark
the meadow is clipped short.
She is full of strength and energy, but she panics
in the dark as before and grows abnormally thin overnight.
The cow does this over and over,
and this is all she does.
She never thinks, This meadow has never failed
to grow back. Why should I be afraid every night
that it won't. The cow is the bodily soul.
The island field is this world where that grows
lean with fear and fat with blessing, lean and fat.
White cow, don't make yourself miserable
with what's to come, or not to come.
Wednesday, April 8, 2015
Android Meets Python And they have a picture together!
I recently wrote a simple script to take a picture from an android phone through Python in SL4A and send it over the network through socket programming to a client which saves it to file. Below is the code for the client on android! Please be sure to change your IPs. A couple of other things, SL4A Python is not working in Android 5.0+. I tested this code successfully on Android 4.4 camera phone as the client and my PC running Windows 7 as the server. If you need more information you can check this out: http://faculty.pieas.edu.pk/fayyaz/ippy/html_demos/android.html
Android Client
Exported from Notepad++
Exported from Notepad++
Android Client
# Client code (for android!)
import sys
import os
import android
import socket
droid = android.Android()
fpath = '/sdcard/foo.jpg'
droid.cameraInteractiveCapturePicture(fpath)
s = socket.socket()
s.connect(('192.168.233.1',9999))
droid.makeToast('Connected!')
if os.path.isfile(fpath):
str = "file exists...!"
else:
str = "nope...!"
droid.makeToast(str)
with open (fpath, "rb") as f:
l = f.read(1024)
while (l):
s.send(l)
l = f.read(1024)
s.close()
droid.makeToast('Success!')
#Server code
import socket
import sys
s = socket.socket()
s.bind(('192.168.233.1',9999))
s.listen(10)
sc, address = s.accept()
print address
l = sc.recv(1024)
with open ("pic2.jpg",'wb') as f:
while (l):
f.write(l)
l = sc.recv(1024)
sc.close()
s.close()
Python Multiprocessing
I created a buffered sender and receiver application to demonstrate multiprocessing in Python. The sender computes some fictitious data and sends it to the receiver which writes it to a file. The data is sent when the buffer is filled up. The receiver is slow (due to a delay) and it demonstrates how multiprocessing can allow you to acquire data from a fast source without missing any data and write it to file! You can use similar ideas to write data acquired from a hardware device to the hard-disk without keeping the device tied-up when the data is being written to the file.
from multiprocessing import Process, Queue
import time
def receiver(queue):
## Read from the queue
index = 0
with open("test.txt",'w') as file:
while True:
msg = queue.get() # Read from the queue and do nothing
if (msg == 'DONE'):
break
elif not len(msg):
continue
for m in msg:
file.write(str(m)+"\n")
time.sleep(0.1) # Some expensive operation (plotting or other processing)
print index, len(msg)
index+=1
def sender(count, queue):
## Write to the queue. Sending does not stop if receiver is busy.
bsize = 1000 #buffer size
buff = []
for ii in xrange(0, count):
# d = usbdata
buff.append(d)
if len(buff)==bsize: #Buffer is filled up!
#time.sleep(0.1)
queue.put(buff) # Write 'count' numbers into the queue
buff = []
queue.put(buff)
queue.put('DONE')
print "Sender is done"
if __name__=='__main__':
count = 10**4
queue = Queue() # receiver() reads from queue
# sender() writes to queue
receiver_p = Process(target=receiver, args=((queue),))
receiver_p.daemon = True
receiver_p.start() # Launch receiver() as a separate python process
_start = time.time()
sender(count, queue) # Send a lot of stuff to receiver()
receiver_p.join() # Wait for the receiver to finish
print " %s numbers took %s seconds" % (count,
(time.time() - _start))
Scrambled Eggs
Often we need to make a list of multiple choice questions and generate a copy of the test with the options scrambled or shuffled. For this purpose I have developed a VBA Macro that can do this for you automatically! You can see the code at https://github.com/foxtrotmike/scrambled-eggs. It also contains comments on how to use it.
Monday, March 16, 2015
Ghalib's observations of Hydrogen Bonding
Ghalib's observations of Hydrogen Bonding
Ghalib (1797-1869) in one of his most famous ghazals says:
بسکہ ہوں غالب اسیری میں بھی آتش زیر پا
موے آتش دیدہ ہے حلقہ میری زنجیر کا
This verse can be roughly translated as follows: I am restless in captivity as if there were a fire under my feet. It is this fire that has caused steel to curl to form the links of the chain around my ankles much like a hair that coils when exposed to heat!
I know hairs are proteins and like a good proteins person, I am, at this time, more interested in knowing why does a hair curl when exposed to heat? Just to verify Ghalib's observation, I took out a hair and exposed it to heat to see it curl.
I have been looking on the Internet and have found the following explanation of this phenomenon.
A hair is a composed of keratin protein fibers. Keratin has a coiled coil structure (http://proteopedia.org/wiki/index.php/Keratins). The keratin in the hair is held together by hydrogen bonds. These hydrogen bonds act as glue and can change due to heat or water. On the application of heat, the hydrogen bond structure is disrupted which causes the hair to change its shape. This is the principle on which curling irons are based! However, the hair can recover its shape after some time especially with the addition of water if the amount of the initially applied heat is small!
However, the coiled coil protein structure of keratin is stabilized by hydrophobic interactions. I wonder what role these might play in the change in the shape of the hair when heat is applied.
Wednesday, February 18, 2015
Memory, History and Immortality
"Something lives only as long as the last person who remembers it. My people have come to trust memory over history. Memory, like fire, is radiant and immutable while history serves only those who seek to control it, those who douse the flame of memory in order to put out the dangerous fire of truth. Beware these men for they are dangerous themselves and unwise. Their false history is written in the blood of those who might remember and of those who seek the truth."
Navajo Saying in the X-Files.
Subscribe to:
Comments (Atom)