Microsoft Popfly

So today I got an invite for microsoft’s popfly . Popfly seems to be msfts take on letting users create mashups, websites , communities etc without typing in a single line of code and is powered by silverlight. The key word here being “user” which means anyone can create a mashup without knowing how things work behind the scenes.

The site is in alpha, and there are definitely some issues that I have come across. But the UI is amazing, it works with firefox ( big plus ! ).

I will be messing around with this and see what mashups I can come up with. Please feel free to add me as a friend ( http://www.popfly.ms/users/Kashif ) and I will post invites for users as soon as I get them 🙂

Vice Funds

I read about vice funds a while back on fark.com. From the site the fund invests in alcohol, tobacco, gaming, aerospace and defense stocks. It is an interesting concept because in many ways people are addicted to this stuff and they have had very nice yearly returns ( close to 14.3%/yr ) to back their idea.

Now for anyone who still reads this would you invest in it ? Abhi , I think I already know your answer 🙂

I need to start posting stuff here again ….

Roman Numeral Converter

One more codegolf challenge:-

In this challenge, you will be given a number in roman numeral form and must print out its integer value.

( from codegolf)

My latest solution at 129 bytes:-

r,l,s={‘M’:1000,’D’:500,’C’:100,’L’:50,’X’:10,’V’:5,’I’:1},1000,0

for j in raw_input():s+=r[j]-(0,l*2)[r[j]>l];l=r[j]

print s

Any other ideas ?

Update:

After manzo’s comment, I searched a little and came up with this. Right now its at 119 bytes

r,l,s=dict(M=1000,D=500,C=100,L=50,X=10,V=5,I=1),1000,0

for j in raw_input():s+=r[j]-(0,l*2)[r[j]>l];l=r[j]

print s

Colors for Visual Studio

Having watched a lot of videos featuring textmate, I really liked the color scheme that was being used by a lot of the videos. After some searching I came across Scott Hanselmans blog where he suggests some colors that bring it quite close.

This is what my current setting looks like:-

Any ideas for the colors of the html tag names other than white ?


Codegolf

Ive been working on this codegolf challenge recently which I found quite fun to do (codegolf == accomplish a challenge in code using least amt of lines )

The challenge in question:-

The game of REVERSE requires you to arrange a list of numbers in numerical order from left to right. To move, you tell the computer how many numbers (counting from the left) to reverse. For example, if the current list is 2 3 4 5 1 6 7 8 9 and you reverse 4, the result will be 5 4 3 2 1 6 7 8 9. Now if you reverse 5, you win.

What we’re asking you to do is, given a list of numbers in a random order, produce the moves required to arrange them so they end up in numerical order.

(from codegolf.com)

Now Ive been working on this for a couple of hours and the best I can come up with is this ( My language of choice, python):-

[UPDATE #1]: File Size – 181kb

  1. Changed the while loop condition

2)A different way of printing, by adding a comma after the last object one can suppress the new line that is automatically added by print in python

3)Removing unnecessary indentation helped on the file size

4)Didnt need the strip function

import re,sys n = map(int,re.split(" ",sys.stdin.readline())) l = len(n) while l: m = n.index(max(n[0:l])) + 1 n[:m] = n[m-1::-1] n[:l] = n[l-1::-1] print m,l, l -= 1

[ORIGINAL]

import re,sys n = map(int,re.split(" ",str(sys.stdin.readline()).strip())) l = len(n) while n != sorted(n): m = n.index(max(n[0:l])) + 1 n[:m] = n[m-1::-1] n[:l] = n[l-1::-1] print m,"\n",l l -= 1

the algorithm works in the following way:-

given a list, get its length

find the index of the maximum value within it, do a reverse from 0 to the index, so now the max is in front (and the move being the index + 1)

then do a reverse again on the length of the list , bringing the max to the end of the list (now the move after that being the length of the list)

decrease the length, so you iterate over a smaller list and repeat the same steps on the smaller section of the list

Anyone have anymore ideas to make this shorter ( either the program itself or the algorithm ) ?

C-USA Champions


That was a fantastic game yesterday. Had a lot of fun … definitely need more pictures

Cant argue with this

“You’ve achieved success in your field when you don’t know whether what you’re doing is work or play.” – Warren Beatty

Learning Python

Just started to pick up on Python,

I am sure everyone who took COSC 2320 with Dr. Anderson remembers the word count program. Well after going through some of the tutorials of python here is the same program in python

Not only is it smaller, but its also easier to understand. Hopefully more to follow

import re
import string

#dictionary to store words and their counts
word_count = {}

#read in text document line by line
for line in open("trial.txt").readlines():
    
    #remove leading and trailing whitespace
    line = string.strip(line)

    #split the string into words
    #based on whitespace, punctuation, digits
    for word in re.split("["+string.whitespace+string.punctuation+string.digits+"]",line):
        
        #make the word lower case
        word = string.lower(word)
        
        #check if it is actually a word
        if re.match("^["+string.lowercase+"]+$",word):
            
            #increment count if true
            if word_count.has_key(word):
                word_count[word]+=1
                
            #else add entry
            else:
                word_count[word] = 1

for w in word_count:
    print w, ":" ,word_count[w]

Edit: Some more playing around

import re
import string

word_count = {}

text = open("trial.txt").read();

#list of words delimited by whitespace, punctuation and digits
#iterate by words in returned list from split
#lower case all the words in the text
words =  re.split("["+string.whitespace+string.punctuation+string.digits+"]",string.lower(text))

#go through the list
for i in range(0,len(words)-1):
    
    #as long as the word in the list is a word and is not already a key
    if re.match("^["+string.lowercase+"]+$",words[i]) and not word_count.has_key(words[i]):
        
        #add to the dictionary and get the count from the list
        word_count[words[i]] = words.count(words[i])

for w in word_count:
    print w,":",word_count[w]

Blogger Beta

Finally got into the beta, but where did the rest of the enteries go ? They are back

Previous page (8 / 37) Next page (10 / 37)