Code Is Poetry

Life is Binary

Posts

Vectors in R

#vectors v1 <- c(1,5,11,33)v2 <- c(2,5,11,13)v1+v2v <- rep(0,10)v <- rep(1:10, times=2)vv <- rep(1:10, each=2)vv <- seq(10,20,2)v1 <- 1:5v2 <- 2:10v2 <- c(2,3,4,5,6,7,8)v2v2[2:4]v2[6:9]sd(v2)sum(v2)# summation calculations can be applied over entire vectorsum(v1)

Read more

Matrix creation and selection

# creating matrix(m <- matrix(data=1, nrow = 5, ncol = 4))(m <- matrix(1,3,4))#[,1] [,2] [,3] [,4]#[1,]    1    1    1    1#[2,]    1    1    1    1#[3,]    1    1    1    1#[4,]    1    1    1    1#[5,]    1   ...

Read more

View control redirect from custom view

http://stackoverflow.com/questions/15622736/using-presentviewcontroller-from-uiview UIViewController *currentTopVC = [self currentTopViewController]; currentTopVC.presentViewController......... - (UIViewController *)currentTopViewController { UIViewController *topVC = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; while (topVC.presentedViewController) { topVC = topVC.presentedViewController; } return topVC; }

Read more

R tutorial 1 - igraph

#loading igraph for network analysisrequire(igraph)# creting trivial graphg <- graph(c(1,2, 1,3, 2,3, 3,5),n=5)plot(g)# create random graph with 40 nodes each with 4 childreng <- graph.tree(40,4)plot(g)#diff layout for graph#circleplot(g, layout=layout.circle)#fruchterman.reingoldplot(g, layout=layout.fruchterman.reingold)#graphoptplot(g, layout=layout.graphopt)# interactive graph (graph node can me moved around with mouse select & drag)tkplot(g, layout=layout.graphopt)#3d graph...

Read more

Adding constraints to Auto Layout programmatically

- views have array of contrstaints- can be built with visual format- can also be built with class method on NSLayoutConstraintConstraints with visual formattext based visual format describes constaints  V:[bigBlueView]-55-[caption]:   <------------------------- V indicates vertical constraint, meaning caption should be 55 points below bigBlueView  V:|-49-[bigBlueView]: | indicates the superview, meaning bigBlueView should be 49 points from the top of the...

Read more

Python 5: Classes

class myClass():  def method1(self):    print "myClass method1"      def method2(self, someString):    print "myClass method2: " + someString    class anotherClass(myClass):  def method2(self):    print "anotherClass method2"      def method1(self):    myClass.method1(self);    print "anotherClass method1"      def main(): ...

Read more

jQuery: Div scroll with Page

(function($){var element = $('.follow-scroll'), originalY = element.offset().top;// Space between element and top of screen (when scrolling)var topMargin =20;// Should probably be set in CSS; but here just for emphasis element.css('position','relative'); $(window).on('scroll',function(event){var scrollTop = $(window).scrollTop(); element.stop(false,false).animate({ top: scrollTop < originalY ?0: scrollTop - originalY +...

Read more

Python 4: Loops

def main():  x = 0    # define a while loop  while (x < 5):     print x     x = x + 1  # define a for loop  for x in range(5,10):    print x      # use a for loop over a collection  days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]  for d in days:    print d    # use the break and continue statements  for x in range(5,10):    #if...

Read more

Python 3: Conditional Statements

def main():  x, y = 10, 100  # conditional flow uses if, elif, else    if(x < y):    st= "x is less than y"  elif (x == y):    st= "x is same as y"  else:    st= "x is greater than y"  print st    # conditional statements let you use "a if C else b"  st = "x is less than y" if (x < y) else "x is greater than or equal to y"  print st    # Python does not have support for...

Read more

Python 2: Functions

## Example file for working with functions## define a functiondef func1():  print "I am a function"# function that takes argumentsdef func2(arg1, arg2):  print arg1, " ", arg2# function that returns a valuedef cube(x):  return x*x*x# function with default value for an argumentdef power(num, x=1):  result = 1;  for i in range(x):    result = result * num    return result#function with variable number of argumentsdef multi_add(*args): ...

Read more