Programming for iPad

No Comments

Arduino Chapter I

Finally my Arduino 2009!

No Comments

To quickly test an imap server using telnet


telnet server 143

01 LOGIN username password

02 LIST "" *

03 SELECT mailbox

Line 02 shows you all available mailboxes.

To show the information about a mailbox:

04 STATUS mailbox (MESSAGES)

Between () you can place one or more of the following: MESSAGES, UNSEEN, RECENT UIDNEXT UIDVALIDITY

And one of the following commands to view the a message 1 is the first message * is wildcard for all:

05 FETCH 1 ALL # All IMAP headers

05 FETCH 1 FULL	 # Full headers and body info

05 FETCH 1 BODY	 # Body

05 FETCH 1 ENVELOPE	# Envelope

05 FETCH * FULL # All email

To fully retrieve a message use:

06 UID fetch 1:1 (UID RFC822.SIZE FLAGS BODY.PEEK[])

No Comments

Nokia 5230 isync plugin

Shockingly it doesn’t exist on the Nokia website and the telephone doesn’t appear in the list of the supported!

The solution:

1- Download and unzip this: Nokia 5230 isync plugin

2- Place the bundle in “/Library/PhonePlugins/” (create it if it doesn’t exist yet)

3-Start iSync and add a device as for supported phones!

Have a great syncs :D

, ,

No Comments

Using R for Introductory Statistics

Data

Quickly entering in small data sets is the c function:

>typos = c(2,3,0,3,1,0,0,1)
>typos
[1] 2 3 0 3 1 0 0 1

Note:

  1. The assignment operator is a = and it can be a <-
  2. [1] indicates the the value is a vector

mean function find the mean or average of the data:

> mean(typos)
[1] 1.25

median function find the median of the data:

>median(typos)
[1] 1

var function find the simple variance of the data:

> var(typos)
[1] 1.642857

Data are stored in R as vectors:

> typos.draft1 = c(2,3,0,3,1,0,0,1)
> typos.draft2 = c(0,3,0,3,1,0,0,1)
> typos.draft2 = typos.draft1          #make a copy
> typos.draft2[1] = 0                       #assigne the first page 0 typos
> typos.draft[2]                                #print 2nd pages' value
> typos.draft[-4]                              #print all but 4th page
> typos.draft[c(1,2,3)]                      #fancy, print 1st, 2nd and 3rd


Node:

  1. the period is only used as punctuation
  2. you can’t use an _ (underscore) to punctuate
  3. # is used to make comments
  4. parenteses () are for functions and square brackets [] are for vectors, arrays and lists
  5. the last ex is very important. You can take mode than one value at a time by using another vector of index numbers. This is called slicing

max function find the max of the data:

> max(typos.draft2)
[1] 3

== test the data:

> typos.draft2 == 3   #where are they?
[1] FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE

which test the data and get the indices:

> which(typos.draft2 == 3)
[1] 2 4


or

> n = length(typos.draft2)
> pages = 1:n
> pages
[1] 1 2 3 4 5 6 7 8
> pages[typos.draft2==3]
[1] 2 4

seq is a more general function to produce sequences than ::

> seq(1,n,1)
[1] 1 2 3 4 5 6 7 8

sum and subtracta vector:

> sum(typos.draft2)
[1] 8
> sum(typos.draft2>0)
[1] 4
> typos.draft1-typos.draft2
[1] 2 0 0 0 0 0 0 0

Manipulate a vector:

> x = c(45,43,46,48,51,46,50,47,46,45)
> x = c(x,48,49,51,50,49)
> x
 [1] 45 43 46 48 51 46 50 47 46 45 48 49 51 50 49
> x[16] = 41
> x
 [1] 45 43 46 48 51 46 50 47 46 45 48 49 51 50 49 41
> x[17:20] = c(40,38,35,40)
> x
 [1] 45 43 46 48 51 46 50 47 46 45 48 49 51 50 49 41 40 38 35 40

Edit data using a spreadsheet interface:


> data.entry(x)   #pops up spreadsheet to edit data
> x = de(x)        #same only, doesn't save changes
> x = edit(x)      #uses editor to ediz x

The variable x needs to be defined previously

running maximum and minimun of a set of data


> cummax(x)
 [1] 45 45 46 48 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51
> cummin(x)
 [1] 45 43 43 43 43 43 43 43 43 43 43 43 43 43 43 41 40 38 35 35

define new functions


> std = function(x) sqrt(var(x))
> std(x)
[1] 4.558393

standard deviation built-in command


> sd(x)
[1] 4.558393

difference between near elements in data


> diff(x)
 [1] -2  3  2  3 -5  4 -3 -1 -1  3  1  2 -1 -1 -8 -1 -2 -3  5

rangeretrieve the max and min elements in data


> range(x)
[1] 35 51
> diff(range(x))
[1] 16

Univariate Data

Categorical Data

tableallows to look at tables


> x = c("Yes","No","No","Yes","Yes")
> table(x)
x
 No Yes
  2   3

factorsallows to look at tables


> x = c("Yes","No","No","Yes","Yes")
> table(x)
x
 No Yes
  2   3

Numerical Data

, , , ,

No Comments

Latex Test Post

i\hbar\frac{\partial}{\partial t}\left|\Psi(t)\right>=H\left|\Psi(t)\right>

\LaTeX

\setlength{\unitlength}{0.8cm}\begin{picture}(6,5)\put(1,0.5){\line(2,1){3}}\put(4,2){\line(-2,1){2}}\put(2,3){\line(-2,-5){1}}\put(0.7,0.3){A}\put(4.05,1.9){B}\put(1.7,2.95){C}\put(3.1,2.5){a}\put(1.3,1.7){b}\put(2.5,1.05){c}\end{picture}

, , ,

No Comments

The ssl perfect guide

Unfortunately this website doesn’t have a name, nerthless the explanations are really accurate:

http://209.197.80.93/article/setting-ssl-certificates-apache

, , ,

No Comments

Threading in iPhone programming

As Kdl pointed out, it is a good point to remind the threading skeleton proposed during the Stanfor CS 192P iPhone programming course.

/  LetsMakeAThreadAppDelegate.m
//  LetsMakeAThread
//
//  Created by Evan Doll on 10/27/08.

#import "LetsMakeAThreadAppDelegate.h"

@implementation LetsMakeAThreadAppDelegate

@synthesize window;
@synthesize spinner;
@synthesize answerLabel;
@synthesize button;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    answerLabel.text = @"";

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}

- (IBAction)beginDeepThought:(id)sender
{
    [spinner startAnimating];
    button.hidden = YES;

    [NSThread detachNewThreadSelector:@selector(backgroundThinking) toTarget:self withObject:nil];
}

- (void)backgroundThinking
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [NSThread sleepForTimeInterval:5];
    [self performSelectorOnMainThread:@selector(didFindAnswer:) withObject:@"42" waitUntilDone:NO];
    [pool release];
}

- (void)didFindAnswer:(NSString *)answer
{
    [spinner stopAnimating];
    answerLabel.text = answer;
}

- (void)dealloc {
    [window release];
    [spinner release];
    [answerLabel release];
    [button release];

    [super dealloc];
}

@end

In his post, Kdl point out also how to set lock on variables and how to implement a cache.

- (void)someMethod
{
        [myLock lock];
        // We only want one thread executing this code at once
        [myLock unlock]
}

- (UIImage *)cachedImageForURL:(NSURL *)url
{
    id cachedObject = [cachedImages objectForKey:url];
    if (cachedObject == nil) {
        // Set the loading placeholder in our cache dictionary.
        [cachedImages setObject:LoadingPlaceholder forKey:url];

        // Create and enqueue a new image loading operation
        ImageLoadingOperation *operation = [[ImageLoadingOperation alloc] initWithImageURL:url target:self action:@selector(didFinishLoadingImageWithResult:)];
        [operationQueue addOperation:operation];
        [operation release];
    } else if (![cachedObject isKindOfClass:[UIImage class]]) {
        // We're already loading the image. Don't kick off another request.
        cachedObject = nil;
    }

    return cachedObject;
}

- (void)didFinishLoadingImageWithResult:(NSDictionary *)result
{
    NSURL *url = [result objectForKey:@"url"];
    UIImage *image = [result objectForKey:@"image"];

    // Store the image in our cache.
    // One way to enhance this application further would be to purge images that haven't been used lately,
    // or to purge aggressively in response to a memory warning.
    [cachedImages setObject:image forKey:url];

    [self.tableView reloadData];
}

// Package it up to send back to our target.
NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:image, ImageResultKey, imageURL, URLResultKey, nil];
[target performSelectorOnMainThread:action withObject:result waitUntilDone:NO];

P.S.: Sorry KDL, I actually copied your code, but your code and pre tags didn’t look good on my browser!

, , ,

No Comments

Dovecot configuration

Configuring dovecot to let postfix using it to authenticate clients. Here is my complete dovecot.conf the postfix needed section stand just with the definition of the listening socket

protocols = imap imaps pop3 pop3s
disable_plaintext_auth = no
log_timestamp = "%Y-%m-%d %H:%M:%S "
ssl_disable = no
mail_privileged_group = mail
protocol imap {
}
protocol pop3 {
  pop3_uidl_format = %08Xu%08Xv
}
auth default {
  mechanisms = plain login
  passdb pam {
  }
  user = root
  socket listen {
      path = /var/spool/postfix/private/auth
      mode = 0660
      user = postfix
      group = postfix
    }
  }
}
dict {
}
plugin {
}

, , , , , ,

No Comments

Testing a postfix server

Never forget ho to test a postfix server, both in plain and in ssl:

Original Website

, ,

No Comments