i2devlabs Blog

  • rss
  • archive
  • Supporting CORS and OPTIONS in ServiceStack

    To enable CORS headers and HTTP OPTIONS method in ServiceStack, add the following code to Configure()

     this.Plugins.Add(new CorsFeature());
    
     this.RequestFilters.Add((httpReq, httpResp, requestDto) => {
           if(httpReq.HttpMethod == "OPTIONS"){
                   httpResp.EndServiceStackRequest();
       }
    });
    
    • 1 month ago
    • #C ServiceStack CORS OPTIONS
  • Working hardThat’s Real Racing HD on the iPad :-)

    Working hard

    That’s Real Racing HD on the iPad :-)

    • 4 months ago
    • #JustMigrated
  • Friday Talk: AngularJS

    Cátia is more and more into frontend development and she talked about AngularJS.

    AngularJS basics from i2devlabs
    • 5 months ago
    • #JustMigrated
  • Friday Talk: Isolation Levels in SQL Server 2012

    Luís reformated the talk he gave past October about Sql Server isolation levels and concurrency and here is the result.


    ISOLATION LEVELS?

    Isolation Levels exist so that users can control various concurrency problems when creating reading, updating and deleting data from a database. The concurrency problems are the following:

    Note: The examples will run assuming that there is only one row in the TestTable, that is {id = 1, Value = 1}, the isolation level will be READ UNCOMMITED, that is the lowest level and allows us to test all the following problems.

    Dirty Read

    Dirty read happens when selected data is being changed by a transaction, but it was not committed.

    Example:

    Transaction 1:

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
    BEGIN TRAN
    Select Value from TestTable where id = 1
    COMMIT

    Transaction 2:

    BEGIN TRAN
    UPDATE TesteTble SET Value = 2 where id = 1
    --Simulate having some intensive processing here with a wait
    WAITFOR DELAY '00:00:10'
    ROLLBACK

    If we run the transaction simultaneous, Transaction 1 will tell us that Value is 2, but Transaction 1 is not yet committed, the data we are reading is only valid for 10 seconds.

    Non-Repeatable Read

    Non-Repeatable Read is when two selects to the same data under the same transaction return different data.

    Example

    Transaction 1:

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
    BEGIN TRAN
    Select Value from TestTable where id = 1
    WAITFOR DELAY '00:00:10'
    Select Value from TestTable where id = 1
    COMMIT

    Transaction 2:

    BEGIN TRAN
    UPDATE TestTable SET Value = 2 where id = 1
    --Simulate having some intensive processing here with a wait
    WAITFOR DELAY '00:00:05'
    ROLLBACK

    If we run the transaction simultaneous, Transaction 1 will tell us that Value is 2 in the first select and in the second we will have that the Value is 1.

    Phantom Reads

    Phantom Reads is when 2 selects to the same data under the same transaction return different number of rows.

    Example

    Transaction 1:

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
    BEGIN TRAN
    Select * from TestTable
    WAITFOR DELAY '00:00:10'
    Select * from TestTable
    COMMIT

    Transaction 2:

    BEGIN TRAN
    Insert Into TestTable (Value) Values (2)
    --Simulate having some intensive processing here with a wait
    WAITFOR DELAY '00:00:05'
    ROLLBACK

    If we run the transaction simultaneous, Transaction 1 will tell us TestTable has 2 rows {id = 1, Value = 1} and {id = 2, Value = 2}, but the second select will only return 1 row {id = 1, Value = 1}.

    SQL SERVER ISOLATION LEVELS

    Read Uncommitted

    Read Uncommitted is the lowest Level (Optimistic) and is when reading operations do not respect locks and don’t lock data, has we said before all concurrency problems can occur with this isolation level.

    • Dirty Read – Yes
    • Non-Repeatable Read – Yes
    • Phantom Reads – Yes

    Read Committed

    Read Committed is when reading operation can’t read data that is being changed by another transaction a Dead Lock will occur.

    • Dirty Read – No
    • Non-Repeatable Read – Yes
    • Phantom Reads – Yes

    Snapshot

    Snapshot is only available in SQL Server. In this level, a reading operation will return data that is being changed by another transaction, but without the changes made by it.

    • Dirty Read – No
    • Non-Repeatable Read – Yes
    • Phantom Reads – Yes

    Serializable

    Serializable is the highest Level (Pessimistic) and is when rows and tables being read by a transaction will be locked, Dead Lock will occur in update, insert and delete operations.

    • Dirty Read – No
    • Non-Repeatable Read – No
    • Phantom Reads – NO

    Repeatable Read

    Repeatable Read is when rows being read by a transaction will be locked, a deadlock will occur in update operations.

    • Dirty Read – No
    • Non-Repeatable Read – No
    • Phantom Reads – Yes
    • 5 months ago
    • #JustMigrated
  • Carpenter programmerThat’s Luis Torres right there!

    Carpenter programmer

    That’s Luis Torres right there!

    • 5 months ago
    • #JustMigrated
  • Friday Talk: Command Line Interface basics in Linux

    Last Monday, it was y turn to present the Friday Talk (I know, it’s never on Friday). Lately we have been working on Windows and .NET, and both Luís and Cátia are a tad green on a Linux shell, so I decided to refresh the basics of using the shell on Linux (Ubuntu). The support for this talk wasn’t a slidedeck, it was the following plain text.


    Bash CLI (Command Line Interface) basics in Linux (Ubuntu)

    Getting help

    Use man to show the manual for a command

    Try man man

    File & directory

    1. ~ (tilde) is your home directory, tipically /home/user
    2. pwd (stands for print working directory) returns the directory you are in
    3. ls (list) lists the files in a directory
    4. cd (change directory)
    5. cp (copy) copy a file. For directories, use the -r flag cp -r directory foo (copy recursively)
    6. mv (move) move a file to a different location or rename a file
    7. rm remove a file
    8. rmdir delete empty directory. To delete a directory and it’s contents rmdir -r
    9. mkdir to create a new directory
    10. sudo execute a command as root (dangerous stuff)

    Running a file

    1. ./filename

    System information

    1. df displays filesystem disk space usage for all mounted partitions. df -h is more useful, being -h the flag for “human-readable”
    2. top (table of processes) displays running processes and system resources
    3. free displays the amount of free and used memory. free -h (human-readable) shows values in megabytes, and is probably more useful
    4. uname -a prints all system information, inclunding machine name, kernel name & version and more details.
    5. lsb_release -a prints version information for the Linux release

    User management

    1. adduser newuser creates a new user called “newuser”
    2. passwd someuser changes the password for “someuser”
    3. addgroup newgroup creates a new group called “newgroup”
    4. useradd -G groupname username creates a new user called “username” and adds it to group “groupname”
    5. usermod -a -G sftp pedro adds the existing user “pedro” to the group “sftp”
    6. -G for secondary groups, -g for primary groups
    7. id user shows the id for the user
    8. groups user prints the groups to which the user belongs
    9. su username The su command is used to become another user during a login session. Invoked without a username, su defaults to becoming the superuser.

    File permissions

    In Linux and Unix, eveything is a file. Directories are files, files are files and devices are files.

    • types of access:
      • read (r or 4)
      • write (w or 2)
      • execute (x or 1)
    • user restrictions

      • owner
      • group
      • other
    • chmod change permissions

    • chown change file owner
    • apt-get install acl for more granular permissions

    Text

    1. cat concatenate files and print on the standard output.
    2. grep find a string in a file or stream. It can be used with Regular expression to be more flexible at finding strings.
    3. awk pattern scanning and processing language. It’s a beast and I’m not going to discuss it here. More details http://www.grymoire.com/Unix/Awk.html)
    4. sed stream editor. Simple example: sed s/day/night/ old.txt > new.txt. A powerful tool as seen here http://www.grymoire.com/Unix/Sed.html

    Networking

    1. ifconfig (interface configuration) configure, control, and query TCP/IP network interface parameters
    2. ping
    3. traceroute
    4. nslookup

    Piping

    The pipe makes the output of a command the input for another program. Piping is achieved using the | character.

    ls -l | grep 'init' | less

    xargs

    cat files.txt | cp but this does cat files.txt | xargs cp because cp doesn’t read input, only arguments.

    backticks

    cp `cat files.txt`

    Shell runs the command ct files.txt, intercepts the standard output and uses the result as parameters to cp

    Directing output

    Consider this example ls -l > temp.txt where the output of ls -l is redirected from the screen to a text file. With the > character, it the file exists, it will be replaced. To append to a text use >>

    ls -l >> temp.txt

    Reversing also works_

    grep 'init' < temp.txt

    grep 'init' < temp.txt > temp2.txt

    Shell scripting

    #!/bin/bash
    echo "The simplest of the scripts"
    exit 0
    1. Every shell script starts with #!, frequently called Sha-bang
    2. #! is the magic number. When the kernel goes to run a program, it looks at the first 16 bits of the file. Simply put, it tells the kernel to execute the file contents with the tool specified after the sha-bang

    Some other sha-bang lines you can use:

    #!/bin/sh
     #!/bin/bash
     #!/usr/bin/perl
     #!/usr/bin/tcl
     #!/bin/sed -f
     #!/bin/awk -f
     #!/bin/python

    Note: the file containing the shell script must be executable chmod +x in order to be run like this ./script

    Processes

    1. ps aux lists all running processes
    2. kill -signal pid send the signal “signal” to process with id “pid”. Omit “signal” to just terminate the process
    3. kill -9 pid send signal number 9 (SIGKILL) to process with id “pid”. This is a last-resort method to terminate a process.
    4. command & runs command in the background

    Useful things

    • touch change file timestamp, creating file if it doesn’t exist

    Sources

    https://help.ubuntu.com/community/UsingTheTerminal

    http://en.wikipedia.org/wiki/Ifconfig

    https://help.ubuntu.com/community/FilePermissions

    https://help.ubuntu.com/10.04/serverguide/network-configuration.html

    http://www.faqs.org/faqs/unix-faq/faq/part3/section-16.html

    http://en.wikipedia.org/wiki/Xargs

    http://help.lockergnome.com/linux/help-understand-pipe-xargs—ftopict549399.html

    http://www.ece.ucy.ac.cy/courses/ece306/Linux%20primers/LinuxBasics.pdf

    • 6 months ago
    • #JustMigrated
  • Friday Talk: Python generators

    Today isn’t Friday, but last Friday the team was working at full speed closing features and client requests, so the talk was postponed for today, Monday. It was Catia turn to present, and she chose to talk about Python generators.

    Python Generators from i2devlabs
    • 6 months ago
    • #JustMigrated
  • Friday Talk: Concurrency in SQL Server

    Luís, our in-house Microsoft evangelist, talked about concurrency in SQL Server. His slides were in portuguese, so as soon as he rewrites them in english, this post will be updated with the slidedeck.

    Edit: Luís talk is available in this post http://blog.i2devlabs.com/friday-talk-isolation-levels-in-sql-server-20

    • 7 months ago
    • #JustMigrated
  • Friday Talk: JavaScript inheritance

    Today we started a new initiative called Friday Talks. Every Friday a team member does a presentation to other team members on a topic he or she chooses. These talks are meant to be small, no more than one hour, and no topic is too small. The whole idea is to share with others that little bits of investigation and reading we (at least I) do on the couch, in the evening.

    I was the first one to present and I talked about JavaScript inheritance. Check out the slides.

    2012 oct-12 - java script inheritance from i2devlabs
    • 7 months ago
    • #JustMigrated
  • Apresentação de proposta de estágio no Instituto Politécnico de Leiria

    No passado dia 26 de Junho estive no Instituto Politécnico de Leiria a apresentar a i2devlabs e a nossa proposta de estágio aos alunos do Mestrado em Engenharia Informática - Computação Móvel.

    Podem ver o vídeo aqui:

    Se não quiserem ver o vídeo, podem ver só os slides:

    • 10 months ago
    • #JustMigrated
© 2013 i2devlabs Blog
Next page
  • Page 1 / 2