First Song v2

Feb 21 2012

The second version of my first try to make music with my new USB MIDI adapter.

  • Keyboard: Yamaha YPT-220
  • Software: Sekaiju 2.8 (Free GPL, Windows 7 64b)
  • MIDI to MP3 converter: http://solmire.com
  • Video Software: Microsoft Windows Movie Maker
  • This work is available in MIDI or MP3 format for free if anyone is interested

Comments are off for this post

Update needed

Feb 17 2012

I’ve been very busy lately. The good news is that I have tons of painting to upload. But at the moment writing is not my first priority. However, I read weblogs of web development celebrities almost on a daily basis.

Comments are off for this post

Lua function to traverse all files in a folder recursively

Jan 12 2012

Here is a little function that uses Lua File System (lfs module) in order to traverse all the files in a folder and its sub folders (and their sub folders) recursively.

DIR_SEP="\\" --should be "/" for Unix platforms (Linux and Mac)
function browseFolder(root)
	for entity in lfs.dir(root) do
		if entity~="." and entity~=".." then
			local fullPath=root..DIR_SEP..entity
			--print("root: "..root..", entity: "..entity..", mode: "..(lfs.attributes(fullPath,"mode")or "-")..", full path: "..fullPath)
			local mode=lfs.attributes(fullPath,"mode")
			if mode=="file" then
				--this is where the processing happens. I print the name of the file and its path but it can be any code
				print(root.." > "..entity)
			elseif mode=="directory" then
				browseFolder(fullPath);
			end
		end
	end
end

--this is a sample call
browseFolder(".")

Comments are off for this post

Checking IP address format in Lua

Jan 09 2012

Here is a little function that I developed to test if a string is a valid IPv4 address (that is 4 numbers between 0 to 255 separated with “.”)

---checks if a string represents an ip address
-- @return true or false
function isIpAddress(ip)
 if not ip then return false end
 local a,b,c,d=ip:match("^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)$")
 a=tonumber(a)
 b=tonumber(b)
 c=tonumber(c)
 d=tonumber(d)
 if not a or not b or not c or not d then return false end
 if a<0 or 255<a then return false end
 if b<0 or 255<b then return false end
 if c<0 or 255<c then return false end
 if d<0 or 255<d then return false end
 return true
end

And here are some tests:

assert(isIpAddress("1.1.1.1")==true)
assert(isIpAddress("255.1.1.1")==true)
assert(isIpAddress("255.255.0.0")==true)
assert(isIpAddress("0.0.0.0")==true)
assert(isIpAddress("255.255.255.255")==true)
assert(isIpAddress("0.0.0.1")==true)
assert(isIpAddress("0.0.1.1")==true)
assert(isIpAddress("0.1.1.1")==true)
assert(isIpAddress("1.2.3.4")==true)
assert(isIpAddress(nil)==false)
assert(isIpAddress("")==false)
assert(isIpAddress("1")==false)
assert(isIpAddress("1.2")==false)
assert(isIpAddress("1.2.3")==false)
assert(isIpAddress("1.2.3.4.")==false)
assert(isIpAddress(".1.2.3.4")==false)
assert(isIpAddress("0")==false)
assert(isIpAddress("-1")==false)
assert(isIpAddress("256")==false)
assert(isIpAddress("-1.2.3.4")==false)
assert(isIpAddress("1.-2.3.4")==false)
assert(isIpAddress("1.2.-3.4")==false)
assert(isIpAddress("1.2.3.-4")==false)
assert(isIpAddress("256.2.3.4")==false)
assert(isIpAddress("1.256.3.4")==false)
assert(isIpAddress("1.2.256.4")==false)
assert(isIpAddress("1.2.3.256")==false)
assert(isIpAddress("256.256.256.256")==false)
assert(isIpAddress("1000.0.0.0")==false)
assert(isIpAddress("a.b.c.d")==false)
assert(isIpAddress("a.2.c.d")==false)
assert(isIpAddress("a.b.3.d")==false)
assert(isIpAddress("a.b.c.4")==false)

Comments are off for this post

What are all the valid subnet masks

Jan 09 2012

Here are all the valid subnet masks for IPv4:

  1. 128.0.0.0
  2. 192.0.0.0
  3. 224.0.0.0
  4. 240.0.0.0
  5. 248.0.0.0
  6. 252.0.0.0
  7. 254.0.0.0
  8. 255.0.0.0
  9. 255.128.0.0
  10. 255.192.0.0
  11. 255.224.0.0
  12. 255.240.0.0
  13. 255.248.0.0
  14. 255.252.0.0
  15. 255.254.0.0
  16. 255.255.0.0
  17. 255.255.128.0
  18. 255.255.192.0
  19. 255.255.224.0
  20. 255.255.240.0
  21. 255.255.248.0
  22. 255.255.252.0
  23. 255.255.254.0
  24. 255.255.255.0
  25. 255.255.255.128
  26. 255.255.255.192
  27. 255.255.255.224
  28. 255.255.255.240
  29. 255.255.255.248
  30. 255.255.255.252
  31. 255.255.255.254

The following Lua script was used to calculate those values:

map={
  ["00000000"]="0",
  ["10000000"]="128",
  ["11000000"]="192",
  ["11100000"]="224",
  ["11110000"]="240",
  ["11111000"]="248",
  ["11111100"]="252",
  ["11111110"]="254",
  ["11111111"]="255"
}
for i=1,31 do
  s=string.rep("1",i)..string.rep("0",32-i)
  print(map[s:sub( 1, 8)].."."..map[s:sub( 9,16)].."."..map[s:sub(17,24)].."."..map[s:sub(25,32)])
end

Comments are off for this post

New paper

Jan 01 2012

image

Apparently back side of the paper I have is much better than its front side!

Comments are off for this post

Setting up Tele2 Huawei e367 3G modem on Linux (Ubuntu 11.04)

Dec 31 2011

I needed to connect my Tele2 usb modem to Ubuntu and here is a good solution.

It’s basically these lines that made it work:

$ cd /etc/usb_modeswitch.d
$ sudo tar xzf /usr/share/usb_modeswitch/configPack.tar.gz 12d1:1446
$ sudo sed -i -e 's/14ac"/14ac,1506"/' 12d1\:1446

Also it seems that the following command is required for it to work:

$ sudo modprobe usbserial vendor=0x12d1 product=0x1506

After that, you need to configure Ubuntu Network Connections (the little network icon on the top right of the screen near the speaker icon). Go to “Mobile Broadband” tab, click “Add”. Select “Sweden” as your country, “Tele2″ as your operator and “Mobile Bredband” as your data plan.
Then use the following configurations:

  • PIN1: ***** (your pin code)
  • connection type: NDIS
  • access point: mobileinternet.tele2.se
  • Phone number: *99#
  • Username and password: Not used (leave empty)
  • Password Authentication Protocol: CHAP (to be safe you can select all of them)
  • IP address: Dynamic
  • DNS address : Dynamic
  • WINS address: Dynamic

PS. The Linux version of the driver is really stable! I share the Internet using an Asus Eee Box and an access point to 4 other wireless devices at home. In Windows, the device used to get disconnected and sometimes it had to be removed from the USB port and inserted again (even when using the latest driver from Huawei). In Linux this hasn’t happened during the last week.

Comments are off for this post

Flying elevator

Dec 29 2011

I don’t know how fast this was going but I am could feel the pressure in my ears when I used this elevator.

Comments are off for this post

Hamed’s woman

Dec 18 2011

Comments are off for this post

Santa

Dec 18 2011

Comments are off for this post

Older posts »