KYKTOMMY

A blog for you and me

Vim in Xcode and Eclipse

Vim in Xcode

Xvim

installation:

  1. git clone the project
  2. open the project
  3. build the project

Vim in eclipse

Vrapper

installation:

  1. open ‘help’ menu in eclipse
  2. select ‘install new software’
  3. paste the url: http://vrapper.sourceforge.net/update-site/stable in the work with: field
  4. press enter to load the link
  5. accept all agreement and continue to finish
  6. restart

notes

they both are in development process
may not support all features of vim

Core Data First Look

basic fetchResultController getter

form template of ios project

  1. setup NSFetchRequest
  2. NSEntityDescription (entity)
  3. fetchRequest setEntity: entity
  4. (set batchSize)
  5. (sortDesciptors)
  6. set fetchResultController delegate with fetch Request and managedObject
  7. catch error

insert new object

  1. get context
  2. get entity
  3. initial NSManagedObject
  4. setValue on the managed object for key
  5. context save -> catch error

initialize managed context

  • NSManageObjectContext: bound to the presistence store
  • NSPersistenStoreCoordinator: support the model (SQLite)
  • NSMangedObjectModel: derived from data model (.xcdatamodeld)

Model -> presistence store -> context

create Core data from scratch

  1. Add Core Data Framework
  2. Create a data model
  3. initialize the data model
  4. initialize the managed object context

MAMP External Folder Config

External folder

MAMP web page location = /Applications/MAMP/htdoc/ Let external folder location = ~/play/fuelphp/

1
2
$ cd /Applications/MAMP/htdoc/
$ ln -s ~/play/fuelphp/ ./fuelphp

and also the mode of the folders should be 644

Scala Beginner

Scala For Beginner

i learn scala during a class teaching java -.-“”.
i am reading ‘Seven Languages in Seven weeks’.
all the examples, code is sourced from this book
ok, lets start.

Expressions

1
2
3
4
5
6
7
  val a = 1

  Nil is a empty list

  //we can't do that
  if(0)
  if(Nil)

Function

1
2
3
def foo {
  ...
}

Loop

1
2
3
4
5
6
7
for( i <- 0 until args.length ) {
  ...
}

args.foreach { arg =>
  println(arg)
}

List

1
2
3
4
5
val list = (1,2,3)
list(2) // Error

val list = List(1,2,3,4)
list(2) // Int = 3

Range

1
2
3
4
5
6
7
val range = 0 until 10
val range = (0 to 10)
range.start // Int = 0
range.end // Int = 10
range.step // Int = 1

(1 to 10) by 5 // (1,5,10

Tuples

1
2
3
4
5
val person = ("Peter", "Joe")
person._1 // Peter
person._2 // Joe

val (x, y) = (1, 2)

Function

1
2
def foo:String { ... }
def bar:String = "hi"

Class

inline class

1
class Person( firstName: String, secondName: String )

Outer & Inner constructor

1
2
3
4
5
6
7
8
9
class Student( name: String ) {
  val name = "Peter"
  val age = 12
  println( "outer constructor" )

  def this( name: string, age: int ) {
    println( "inner constructor" )
  }
}

static attribute in class

1
2
3
4
object Course {
  def name  = println("Physics")
}
Course.name

Inheritance

1
2
3
class Employee(...) extends Person(...) {
  override def hi() = println("hi")
}

Traits ( ruby’s mixins )

1
2
3
4
5
trait Nice {
  def greet() = println("greeting")
}

class Character(...) extends Person(...) with Nice

var v.s. val

var is mutable val is immutable

List

1
2
3
4
5
6
val list = List(1,2,3,4)
list(1) // Int = 2
list(-1) // Int = 1
list(-2) // Int = 1

Nil // = list()

Sets

TODO

XML

XML is treated like a Object
\ “childNodeName”
\ “@attributeName”

Pattern Matching

1
2
3
4
5
val str = "hi"
str match {
  case "" => println( "empty string" )
  case _  => println( "default case" )
}

you can set guard here
case x if x > 0 => foo()

Regular expression

1
2
val reg = """^\w*""".r
println( reg.findFirstIn("abcd") )

Concurrency

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import scala.actors._
import scala.Actor._

case Object OtherObject

class Foo extends Actor {
  def act() {
    react {
      case OtherObject => println( "reacted" )
    }
  }
}

val foo = new Foo().start
foo ! OtherObject

end

Land of Lisp

clisp

install clisp in linux(ubuntu)
1
sudo apt-get install clisp

Variable

global variable (top-level definition)

1
2
3
4
(defparameter *small* 1)
(defparameter *big* 100)

(defvar big 100)

local variable

1
2
3
(let ((a 5)
          (b 6))
  (+ a b))

change variable value

1
(setf *big* 50)  

Function

1
2
(defun function_name (argument)
  ...)

local funciton

1
2
3
4
5
(flet ((f (n)
          (+ n 10))
      (g (n)
          (- n 3)))
  (g (f 5))) ; call func g

call local function from another

1
2
3
4
5
(labels ((a (n)
            (+ n 10))
         (b (n)
            (+ (a n) 20)))
    (b 10))

Symbols, Numbers, String

Symbols are case-insensitive

1
(eq 'fooo `FoOo) ; T 

Numbers with floating point

1
(/ 4 6) ; 2/3 

print out String

1
(princ "Hello world") 

Code Mode & Data Mode

Code Mode is the common code you want to execute

1
(expt 5 3)

Data Mode is you want to print out the code

1
'(expt 5 3)

List

List are a crucial feature in Lisp

  • a empty list = nil
1
2
(list 'pork 'beef 'chicken)
`(cat (duck bat) ant)

Con Cells

[a, ]->[b, ]->[c, ]->nil

1
2
3
4
(cons 'chicken 'cat) ; (CHICKEN . CAT)
(cons 'chicken 'nil) ; (CHICKEN)
(cons 'chicken ()) ; (CHICKEN) where () is a empty list
(cons 'chicken '(beef pork)) ; (CHICKEN BEEF PORK)

car = take away the first slot of a cell cdr = take away the second to end slots cadr = take away the second slot

1
2
(car '(pork beef chicken)) ; (PORK)
(cdr '(pork beef chicken)) ; (BEEF CHICKEN)

Conditions

if

1
2
3
4
5
  (if (= (+ 1 2) 3)
       'yup
       'nope)

; yup

Rvm : Ruby Version Manager

RVM

rvm is a manager controling the version of ruby

user can test different version of ruby, like Jruby, macRuby, ruby 1.9.2, 1.9.3, and changing between them using one command, so cool!

Here is the installation, you can find these in the offical site RVM

installation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#you should install curl and git first!!

user$ sudo bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )

user$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile

user$ source .bash_profile

user$ type rvm | head -1
rvm is a function

user$ rvm list known #show rvm support version
user$ rvm list #show your installed version

user$ rvm install 1.9.3 # or 1.9.3-p0 that works for my ubuntu, if error have a try

user$ rvm use 1.9.3 --default #set default to 1.9.3 & use it

if you are ubuntu/other Linux user, edit the shell as login shell in “Edit > profile preference > title command > command run as login shell”

Learn C the Hard Way

learn code the hard way

thanks for the good site learnCodeTheHardWay this site provide the basic?(to me) tutorials of ruby and c (i am going to learn), and a book of python (not free) Good site (good = with sharing)

Here what i have learn

Code
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>

int main(int argc, char *argv[])
{

  int age = 21;

  printf("kyktommy age: %d", age);

  return 0; //no error

}

compile: CFLAGS=-Wall make filename ./filename

Code inside main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    //print string
  char name[] = "kyktommy";
  printf("my name is %s", name);

  sizeof(int); // 4
  int four_num[4] = {0}; // 4 int is 0
  sizeof(four_num); // 4*4 = 16
  sizeof(four_num)/sizeof(int); // 4 - get the length of array

  //array of chars, using pointer for string, [] for array
  char *names[] = {"mary", "peter", "joe"};
  //pointer to array
  char **cur_name = names;
  //cur_name[0] = *cur_name = names[0] = "mary"

  //argc is arguments count, argv is the real arguments
  //argv[0] is the script name
  int i=0;
  for(i=0; i<argc; ++i) {
      printf("%d arg: %d", i, argv[i]);
  }
  

OK, take a rest here and continue more …

Code inside main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    struct Person {
      char *name;
      int age;
  }; //don't miss that ;

  //this is a mehtod that return [struct Person] type
  struct Person *Person_create {...}

  //create a Person alloc into memory
  struct Person *joe = malloc(sizeof(struct Person));
  joe->age = 100; //edit its field using -> where pointer is used

  //release memory from memory
  free(joe->name); //release what you have alloc into memory
  free(joe);
Code inside main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//function pointer
typedef int (*compare)(int a,int b);
//sort function
void sort(int *arr, compare cmp) {
  ...
  if(cmp(a,b)>0) ...
  ...
}
//method for pointer use
//the return and parameter is the same as "compare"
int sorted_order(int a, int b) {return a-b;}
int reverse_order(int a, int b) {return b-a;}

//int main()
sort(arr, sorted_order)
sort(arr, reverse_order)

Octpress Startup

First thank you octopress give me an environment for starting my blogging.

It is no problem to use wordpress or octpress or others, but you should select one which make you happy.

Using octopress make me feel happy and learn more things, like git, Markdown,Heroku, etc, more in future (FUN).

Setupdocs
1
2
3
4
5
6
7
8
9
10
rvm install 1.9.2 && rvm use 1.9.2

git clone git://github.com/imathis/octopress.git octopress
cd octopress    # If you use RVM, You'll be asked if you trust the .rvmrc file (say yes).
ruby --version  # Should report Ruby 1.9.2

gem install bundler
bundler install

rake install #install Octopress theme
New Post, Page & Deploy to Heroku
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
rake new_post["my new post"] #create new post
rake new_page["my new page"] #create new page, but not shown in menu

gem install heroku
heroku create kyktommy #kyktommy.heroku.com
git config branch.master.remote heroku 

#remove "public" in .gitignore
rake generate #generate to public
git add .
git commit -m 'blog start'
git push heroku master

#if push heroku permission denied
ssh-keygen -C "you-email@email.com" -t rsa #rsa, dsa
heroku keys:add ~/.ssh/id_rsa.pub #id_dsa.pub
git push heroku master

Yah, you have built up you blog.

Here is some Markdown notes

MarkdownMarkdown site
1
2
3
4
5
6
7
8
9
10
11
12
# h1 header
## h2 header 
### h3 header 

__strong tag__

+ list-item1
+ list-item2
+ list-item3

[link name](link url "title")
![alt](image url "title")