Tuesday, August 30, 2011

Leveling in Vim.

Here is a nice guide if you are like me only knowing the basic and essential in Vim.

Learn Vim Progressively

Note: I'm currently on Level 2 :-)

Ubuntu issues?

Well then follow my directions: Ask Ubuntu!


Saturday, August 27, 2011

Magic package - WOL.

Python is fun! Did a script for Wake On Lan.

import socket

mac = "00:00:00:00:00:00" # mac address
decoded = "" # string for converting characters to hex

package = mac.split(':') # remove ':''

# iterate through mac address and convert to hex 2 characters at a time
for x in package:
decoded += x.decode('hex')

macAddress = '\xff'*6+decoded*16 # magic package!

#method for sending magic package
def wakeOnLan(mac):
mySocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
mySocket.sendto(mac, ('255.255.255.255', 9)) # broadcast address and port
mySocket.close()
wakeOnLan(macAddress) # Send it away baby!

---

Short version(where you have to manually edit the mac address):


import socket

macAddress = '\xff'*6+'\x00\x00\x00\x00\x00\x00'*16

def wakeOnLan(mac):
mySocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
mySocket.sendto(mac, ('255.255.255.255', 9))
mySocket.close()
wakeOnLan(macAddress)

get-flash-videos.

We all know that Linux and Flash doesn't play well together, especially if you're on a low spec system like me(laptop with a single core). I usually try to avoid Flash but sometime it's inevitably. This is were the get_flash_videos tool gets handy.

Description:

Download videos from various Flash-based video hosting sites, without having to use the Flash player. Handy for saving videos for watching offline, and means you don't have to keep upgrading Flash for sites that insist on a newer version of the player.

Supports Linux, Windows and OS X - see Installation for more details and how to install.

Includes support for the following sites/players (and more!):

YouTube, eHow, Brightcove (used by many sites like Channel 4, Daily Telegraph ...), BBC (news, etc), Metacafe, 5min, Google, fliqz, nicovideo, vimeo, Blip, Break, Collegehumor, Muzu, Sevenload, Megavideo, Wat.tv.

Also includes a 'generic' method which works on many other sites.

Friday, August 26, 2011

Hug a Tree.

Don't really know why im posting this but me and my daughter went for a walk in the forest last weekend. Really enjoyable, but on our way we came a cross a big tree and decided to give it a hug(don't ask me why).

If you're unsure how to hug here is a guide for you: Hug a Tree




Thursday, August 25, 2011

dmidecode.

I'm was going to upgrade the memory on my server and I was a bit unsure of which type of modules that was supported by the motherboard(DDR2/DDR3?). Couldn't find the manual or type of motherboard. And a second thing is that there is no monitor connected aswell. Well, this is how i solved that.

ssh server

sudo dmidecode --type 17 | more


And voilá!

# dmidecode 2.9
SMBIOS 2.5 present.

Handle 0x0027, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x0025
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 72 bits
Size: 1024 MB
Form Factor: DIMM
Set: None
Locator: DIMM0
Bank Locator: BANK0
Type: DDR2
Type Detail: Synchronous
Speed: 400 MHz (2.5 ns)
Manufacturer: Corsair
Serial Number: 00000000
Asset Tag: AssetTagNum0
Part Number: CM2X1024-6400

Using dmi is just great for a purpose like this!

man dmidecode
dmidecode is a tool for dumping a computer's DMI (some say SMBIOS) ta‐
ble contents in a human-readable format. This table contains a descrip‐
tion of the system's hardware components, as well as other useful
pieces of information such as serial numbers and BIOS revision.


RuntimeError: maximum recursion depth exceeded.

Fooling around with a simple recursive method. Apparently there is an default limit in Python preventing infinite recursion. You can bypass it by using following method of the sys class:

sys.setrecursionlimit(limit)

Set the maximum depth of the Python interpreter stack to limit. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python.

The highest possible limit is platform-dependent. A user may need to set the limit higher when she has a program that requires deep recursion and a platform that supports a higher limit. This should be done with care, because a too-high limit can lead to a crash.


Sample test:

# Simple recursive funcktion in Python
import sys

sys.setrecursionlimit(10000)

def method(arg):
if arg == 0:
print "End."
else:
arg -= 2
print arg
method (arg)

method(10000)




Process big text files in Python.

I'm pretty sure that you could do this in several different and better ways(as usual when it comes to coding). But this is my solution for reading big text files in Python.


from sys import argv

file = argv[1]
input = ""

inputData = open(file)

#Function for reading chuncks

def readChuncks():
return inputData.read(1024)

#Iterate through the file

for data in iter(readChuncks, ''):

input += data #process the data

inputData.close()



Any thoughts/comments/suggestions would be greatly appreciated :-)

Tuesday, August 23, 2011

You can imagine the Hollywood-type of scene where a group of Google engineers collude to delete everybody’s Gmail unless they’re given $3 million

Interesting article:

Keep ideas and information organised!

A great thing for keeping ideas and personal information is to install a local wiki on your computer. I just a great way to document things like code snippets, to do lists and so on.

This is my setup on my main laptop:
  • Lighttpd - A light blazing fast webserver.
  • Dokuwiki - Simple, but a great wiki(stores the pages in files so there's no need for a database server)
  • A simple rsync bash script for backing up the wiki to my main server through the network.



Saturday, August 20, 2011

DuckDuckGo on Time's top 50 websites.

My favorite search engine apparently made it to the top 50 websites of 2011 according to Time's.

So what's DuckDuckGo? Wikipedia summarize it as follow:

DuckDuckGo is a search engine based in Valley Forge, Pennsylvania that uses information from crowd-sourced sites (like Wikipedia) with the aim of augmenting traditional results and improving relevance. The search engine philosophy emphasizes privacy and does not record user information

What's makes this search engine stand out according to me is the privacy policy and the awesome function of what they call bangs. The bang function is simply a search function to search other sites directly.

Type a bang command like:

!amazon mad caddies - which will directly list all the albums of the artist.
!python - math - lists the methods of math class.
!askubuntu nvidia 11.04 - gets issues regarding Ubuntu 11.04 and Nvidia cards.

Other goodies you can use:

md5
password 15 strong
whois duckduckgo.com

And so on, check out all the bangs and goodies on DuckDuckGo.

Note: Try search for "Simpsons characters"

Link to Time's article.:

Like cartoons?

US economy explained in a simple manner.

Friday, August 19, 2011

Stanford University is...

Offering a free online course in databases. Check out following link:



Awesome! I really need to refresh my database knowledge. At this point 22,855 people have signed up(!)

Course Description

This course covers database design and the use of database management systems for applications. It includes extensive coverage of the relational model, relational algebra, and SQL. It also covers XML data including DTDs and XML Schema for validation, and the query and transformation languages XPath, XQuery, and XSLT. The course includes database design in UML, and relational design principles based on dependencies and normal forms. Many additional key database topics from the design and application-building perspective are also covered: indexes, views, transactions, authorization, integrity constraints, triggers, on-line analytical processing (OLAP), and emerging "NoSQL" systems.

Android educational video tutorials

Wanna start develop on the Android platform but you never have the time to read all those boring and ineffective 800 pages books? Well sir, then I have the following excellent video tutorials ready for you:


This is all provided by Bucky Roberts which is the man behind The New Boston(site). This guy is just amazing when it comes to sharing knowledge.

Don't know Bucky? Well, check this out:


Echo "Alright folks let's get it started in here..."

Gonna pinpoint the essence of this blog:

  • Linux
  • Python
  • Android
  • Life

Enjoy!