portella.com.br

Blog pessoal de Felipe Portella

Archive for the ‘Desenvolvimento’ Category

How swype works?

without comments

Nice simple Python code to undestand how swype works:

krishnabharadwaj.info/how-swype-works/

 

—-

 

Swype is an awesome software which makes typing in mobile phones using the qwerty keyboard very easy. This is how it looks:

swype

I was just thinking how this could be implemented. It boils down to a string sub-sequence problem. The path traced by the user consists of all the characters in a word. This is an ideal situation, but many a times, we do not take care of all the characters in between and miss many of them.

Some of the characteristics i have considered:

1. Filtering of words based on the first and last character.
2. Characters which are buried among other characters in the path traversed by the user.
3. The number of traversals between different rows of the keyboard gives us a fair idea about the length of the word.

We can use a number of such characteristics and increase the chances of suggesting the right word. One such hint i can think of is:

Split the words in sets of three characters:
Lets take the case of the word "English" here. The actual trace may be like "edfgbnbghjkliugfdsdfgh"

Groups like bnb, bgh, kli, dsd strongly suggest that there is a turn which signifies a character which has a higher probability of being present in the word.

I wrote a basic version of this using python and this wordlist. Some basic introduction to some of the functional programming used here is discussed in this link

WORDS = open('wordlist.txt').read().split()
KEYBRD_LAYOUT = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm']

def match(path, word):
    """ Checks if a word is present in a path or not. """

    try:
        for char in word:
            path = path.split(char, 1)[1]
        return True
    except : return False

def get_keyboard_row( char ):
    """ Returns the row number of the character """

    for row_no, row in enumerate(KEYBRD_LAYOUT):
        if char in row:
            return row_no

def compress(sequence):
    """ Removes redundant sequential characters. ex : 11123311 => 1231 """
    ret_val = [ sequence[0] ]
    for element in sequence:
        if ret_val[-1] != element:
            ret_val.append(element)
    return ret_val

def get_minimum_wordlength(path):
    """ 
    Returns the minimum possible word length from the path.
    Uses the number of transitions from different rows in 
    the keyboard layout to determin the minimum length
    """
    row_numbers = map(get_keyboard_row, path)
    compressed_row_numbers = compress(row_numbers)
    return len(compressed_row_numbers) - 3

def get_suggestion(path):
    """ Returns suggestions for a given path. """

    suggestions = filter(lambda x: x[0] == path[0] and x[-1] == path[-1], WORDS)
    suggestions = filter(lambda x: match(path, x), suggestions)

    min_length = get_minimum_wordlength(path)
    suggestions = filter(lambda x: len(x) > min_length, suggestions)

    return suggestions

if __name__ == '__main__':
    test_cases = ['heqerqllo',                   # hello
        'qwertyuihgfcvbnjk',                     # quick
        'wertyuioiuytrtghjklkjhgfd',             # world
        'dfghjioijhgvcftyuioiuytr',              # doctor
        'aserfcvghjiuytedcftyuytre',             # architecture
        'asdfgrtyuijhvcvghuiklkjuytyuytre',      # agriculture
        'mjuytfdsdftyuiuhgvc',                   # music
        'vghjioiuhgvcxsasdvbhuiklkjhgfdsaserty', # vocabulary 
        ]

    for test in test_cases:
        print get_suggestion(test)

The results for the same were pretty good.

 ['hello', 'hero', 'ho']
 ['quick']
 ['wed', 'weird', 'weld', 'wild', 'wold', 'word', 'world', 'would']
 ['doctor', 'door', 'dour']
 ['architecture']
 ['adjure', 'agriculture', 'article', 'astute']
 ['music', 'mystic']
 ['vocabulary']

The basic version was working within an hour. I must say that the string split method in python is very well thought of. split( delimiter, 1) returns a the string before and after the first match.

Written by Felipe Portella

maio 23rd, 2013 at 11:53 am

Livro gratuito de programação com NCL

without comments

Written by Felipe Portella

maio 5th, 2012 at 10:16 am

Posted in Desenvolvimento

SCRUM

without comments

Video interessante com uma visão geral da metodologia SCRUM em menos de 10 minutos:

Written by Felipe Portella

janeiro 21st, 2012 at 3:41 pm

Posted in Desenvolvimento

Tagged with

String Format for Double [C#]

without comments

Many samples showing how to format float numbers to string in C#:

www.csharp-examples.net/string-format-double/

Written by Felipe Portella

agosto 23rd, 2011 at 10:45 pm

C# 3.0 and Parallel FX/LINQ in Mono – Ray Trace demo

without comments

Written by Felipe Portella

julho 27th, 2011 at 9:23 am

How to increase UPLOAD MAX FILE SIZE for DREAMHOST?

without comments

Written by Felipe Portella

junho 10th, 2011 at 11:25 pm

Posted in Desenvolvimento

Ofuscamento e Engenharia reversa em .NET

without comments

Nada melhor que entender sobre como fazer engenharia reversa em .NET para entender como melhor proteger o nosso código.  Abaixo eu organizo alguns links sobre essa prática que me ajudaram a escolher melhor que ferramentas usar:

Esse primeiro artigo ensina como remover manualmente os opcodes inválidos e assim conseguir abrir o fonte “protegido” em ferramentas como .NET Reflector ou o dotPeak:

Removing Invalid OpCodes From Obfuscated Assemblies

Já este segundo é uma continuação na qual ele basicamente automatiza o processo:

Hacking Mono.Cecil – allowing invalid opcodes

Alguns outros artigos interessantes:

How to make your Obfuscator fool Reflector

Making NCloak fool Reflector

Protecting your precious code!

Protecting your precious code! – Part 2

Tamper Proofing your Code

Tamper Proofing – an implementation (Part 1)

Tamper Proofing – an implementation (Part 2)

Tamper Proofing – an implementation (Part 3)

 

Este outro site tem uma coleção de utilitários para este tipo de estudo: www.ntcore.com/utilities.php

Written by Felipe Portella

junho 3rd, 2011 at 1:26 pm

NuGet (NuPack): gerenciador de bibliotecas para .NET

without comments

O NuGet, que antes chamava-se NuPack, é um gerenciador de bibliotecas para a plataforma .NET.

O papel do Nuget é justamente ser um gerenciador de bibliotecas de modo a garantir que todas as dll´s de um pacote estejam atualizadas com suas versões corretas evitando assim erros de referência em seus projetos.

Ele é grátis e pode ser usado livremente no Visual Studio 2010. (Se você não tem o VS pode usar no Visual Web Developer 2010 Express)

Você pode obter o Nuget aqui : nuget.codeplex.com/

Após baixar e instalar o Nuget ele se integra automaticamente ao Visual Studio ou Visual Web Developer. O NuGet é uma extensão para o Visual Studio e você pode encontrá-lo no menu Tools/Library Package Manager.

Written by Felipe Portella

junho 2nd, 2011 at 4:34 pm

Problem with VC90 redistributables

without comments

I was facing a problem trying to run my application still compiled in debug in another machine (not a developer one, in other words without Visual Studio installed). Looking the Windows Logs -> Application appears this error:

Activation context generation failed for “C:\Projects\MyProgram.dll”.Error in manifest or policy file “C:\Projects\Microsoft.VC90.DebugCRT.MANIFEST” on line 4. Component identity found in manifest does not match the identity of the component requested. Reference is Microsoft.VC90.DebugCRT,processorArchitecture=”amd64″,publicKeyToken=”1fc8b3b9a1e18e3b”,type=”win32″,version=”9.0.21022.8″. Definition is Microsoft.VC90.DebugCRT,processorArchitecture=”amd64″,publicKeyToken=”1fc8b3b9a1e18e3b”,type=”win32″,version=”9.0.30729.4148″. Please use sxstrace.exe for detailed diagnosis.

The simple way to solve this was to edit the Microsoft.VC90.DebugCRT.MANIFEST file and change the version to the one that I have installed on the machine (in the case the VS 2008 redistributable download from here), so the begining of end file looks like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable></noInheritable>
<assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" 
                        processorArchitecture="amd64" publicKeyToken="1fc8b3b9a1e18e3b">
</assemblyIdentity> 

Written by Felipe Portella

março 14th, 2011 at 11:16 pm

Beginning Google Android Development for .NET Developers – Part 1

without comments

Written by Felipe Portella

fevereiro 21st, 2011 at 10:44 pm

Posted in Desenvolvimento

Tagged with