Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Thursday, June 26, 2014
Monday, October 28, 2013
GIT: Atlassian cheat sheet
Here is link to GIT cheat sheet. Click here to download it
Tuesday, January 29, 2013
Clearing cache for druplal node
cache_get('content:12345:23456', 'cache_content'); # get the data
cache_clear_all('content:nid:vid', 'cache_content') # clear that specific nid/vid combination
cache_clear_all('content:nid', 'cache_content', TRUE) # clear all cached revisions of that nid
Monday, March 22, 2010
Ruby Notes
[Output]
"puts" writes to the screen with a carriage return at the end
"print" does the same thing without the carriage return
[Reading from the Console]
$name = STRDIN.gets
[Functions]
def welcome(name)
puts "hi #{name}" # "#{}" evaluate the variable
end
[Call Functions]
welcome("Mike") or welcome "Mike"
Extra arguments are gathered into the last variable if preceded with a "*"
def test(a=1,b=2,*c)
[Variable]
- Global variables start with '$'
- Class variables start with '@@'
- Instance variable start with '@'
- Local variables, method names, and method parameters start with lower case letter
- Class names, module names and constants start with uppercase letter
- Variable are composed of letters, numbers and underscrores
- Method Names may end with:
'?' - imply a boolean operation
'!' - imply something dangareous, like strings being modified
- __END__ on its own line with no white space, are ignored
- Lines between =begin and =end are ignored
[Collections]
- mystuff = %w{tivo nokia ipaq} # make a string array
- select # populates a new array with members which meet a criteria
[Loops]
for i in 1..4
[Regular Expressions]
- /a/ =~ # find first "a" and return position
- %r{a} =~ # same thing as above
- /p.r/ =~ # matches any character
[Blocks]
Blocks are nameless chunks of code that may be passed as an argument to a function.
def whereisit
yield
end
whereisit {puts "where is the money?" }
where is the money?
- each # iterated through each item of a collection
- detect # returns the first item matching a logical expression
- select # returns all items matching a logical expression
- collect # returns an array created by doing the operation on each element
- inject # is the reducer function in Ruby. "inject" loops over an enumerable and performs an operation on each object and returns a single value
[File I/O]
- Read File into a string:
file = File.new("myfile.txt")
mytext = file.read
- Read an entire file into an array of lines
lines = IO.readlines("data.txt")
- Read a file line by line
file = File.open("file.txt")
while line = file.gets
puts line
end
ensure
file.close # ensure that file is close
end
OR
IO.foreach("data.txt") { |line| puts line }
- Read only a few bytes at at time
require 'readbytes'
file = File.new("myfile.txt")
while bytes = file.readbytes(80)
print bytes+"\r\n"
end
file.close
Friday, March 19, 2010
Ruby: Classes vs. Module
"Ruby Modules are similar to classes in that they hold a collection of methods, constants, and other module and class definitions. Modules are defined much like classes are, but the module keyword is used in place of the class keyword. Unlike classes, you cannot create objects based on modules nor can you subclass them; instead, you specify that you want the functionality of a particular module to be added to the functionality of a class, or of a specific object. Modules stand alone; there is no "module hierarchy" of inheritance. Modules is a good place to collect all your constants in a central location."
Require
require and load take strings as their arguments
[require "sinatra"]
[load "bicycle.rb"]
Include
accpet any number of Module objects
[include Enumerable, Comparable]
Every class ia a module, the include method does not allow a class to be included within another class.
Can mix in more than one module in a class. However, a class cannot inherit from more than one class.
Class names tend to be nouns, while module names are often adjectives.
Source #1
Source #2
Require
require and load take strings as their arguments
[require "sinatra"]
[load "bicycle.rb"]
Include
accpet any number of Module objects
[include Enumerable, Comparable]
Every class ia a module, the include method does not allow a class to be included within another class.
Can mix in more than one module in a class. However, a class cannot inherit from more than one class.
Class names tend to be nouns, while module names are often adjectives.
Source #1
Source #2
Wednesday, March 10, 2010
Metaphone or Double Metaphone
Methaphone / Double Metaphone is an algorithm to match words that are spelled differently, but sound the same. Its useful for avoiding duplicated names in a database.
VIM helpful commands
:sort u (remove duplicate line)
:g/pattern/d (delete line)
:g/^$/d (delete blank lines)
:%s/.*/\U&/ (UPPER CASE)
:%s/.*/\L&/ (LOWER CASE)
:g/pattern/d (delete line)
:g/^$/d (delete blank lines)
Friday, March 5, 2010
POST
- POST is safer than GET
- No restrictions in size
- No Format restrictions. Binary data is also allowed.
- The browser ussually alerts the user that data need to be resubmitted.
- multipart/form-data or application/x-www-form-urlencoded
GET
- GET is less secure compared to POST
- Data in the URL and URL length is restricted
- GET requests are re-executed (Back button/re-submit behavior)
- Only ASCII characters allowed
- application/x-www-form-urlencoded
Tuesday, January 26, 2010
Wiki
Twiki:
http://twiki.org/
DokuWiki:
http://www.dokuwiki.org/dokuwiki
http://twiki.org/
DokuWiki:
http://www.dokuwiki.org/dokuwiki
Monday, August 10, 2009
http-https transitions and relative URLs
Here is good article
Syntax for http/https src='//fast.cdn.net/pix/smiley.jpg'
Syntax for http/https src='//fast.cdn.net/pix/smiley.jpg'
Tuesday, July 21, 2009
VIM TUTORIAL
$ - end of the file/line
1 - beginning of the file
yy - (yank) copy current line (3yy - copy 3 lines)
dd - (delete) cut current line
p - paste (3p paste 3 times)
/ search
? - reverse order search
n - next occurrences in search
:1,$s/test/test (search and replace in the file from beginning)
u - undo
. - repeat last modification
x - delete backwards
A - insert end the of the line
cw - change word
1 - beginning of the file
yy - (yank) copy current line (3yy - copy 3 lines)
dd - (delete) cut current line
p - paste (3p paste 3 times)
/ search
? - reverse order search
n - next occurrences in search
:1,$s/test/test (search and replace in the file from beginning)
u - undo
. - repeat last modification
x - delete backwards
A - insert end the of the line
cw - change word
Tuesday, April 14, 2009
PHP objects, Patterns, and Practice

The book is about OOP and design patterns specifically for PHP5. It also includes chapters for CVS, PHPUnit, Phing, Pear and phpDocumentor. I pleased with reading and information in the book. The book is a good programmer reference.
Tuesday, April 7, 2009
Singleton Pattern
Singleton Pattern is designed to restrict instantiation of a class to one object. The pattern can be used for global variables or database connection.
class Preferences {
private $props = array();
private static $instance;
// cannot be instantiated
private function __construct();
public static function getInstance() {
if ( empty( self::$instance )) {
self::$instance = new Preferences();
}
return self::$instance;
}
public function setProperty( $key, $val ) {
$this->props[$key] = $val;
}
public function getProperty( $key ) {
return $this->props[$key];
}
}
Monday, April 6, 2009
UML - Unified Modeling Language
UML stands for Unified Modeling Language. Abstract classes are represented either by italicizing the class name or by adding {abstract} to the class name. Interfaces are defined in the same was as classes, except they must include a stereotype (<< interface >>). Visibility Symbols:
+ (Public, Available to all code)
- (Private, Available to the current class only)
# (Protected, Available to the current class and its subclasses only)
The UML describes the inheritance relationship as generalization. This relationship is signified by a line leading from the subclass to its parent. The line is tipped with an empty closed arrow.
The UML describes the relationship between an interface and the classes that implement it as realization(- - - |>)
An association occurs when a class property is declared to hold a reference to an instance (or instances) of another class).
Sequence Diagram is object based rather than class based. It is used to model a process in a system step by step.
+ (Public, Available to all code)
- (Private, Available to the current class only)
# (Protected, Available to the current class and its subclasses only)
The UML describes the inheritance relationship as generalization. This relationship is signified by a line leading from the subclass to its parent. The line is tipped with an empty closed arrow.
The UML describes the relationship between an interface and the classes that implement it as realization(- - - |>)
An association occurs when a class property is declared to hold a reference to an instance (or instances) of another class).
Sequence Diagram is object based rather than class based. It is used to model a process in a system step by step.
Wednesday, March 25, 2009
CVS HOW TO
Terminology:
CVS - Concurrent Versions System
RCS - Revision Control System (RCS)
Module - particular set of files kept in CVS
Repository - Location on CVS server where modules are kept
Tag - A certain milestone in a file or module's development
Branch - A fork of the module.
SETUP CVS:
1. export CVSROOT=/cvs (add to the path)
2. cvs init (create depository)
3. cd /home/mike/cvs/project_directory (change directory to projec directory)
4. cvs import -m "Sample Program" project sample start (import project to CVS repository)
5. cvs checkout projectname (get copy of the $projectname. Can be done from Linux(ssh/pserver or Windows(through ssh using WINCVS[http://www.wincvs.org/])
Most Useful Commands:
Add/Update changes to CVS - [cvs commit -m 'Message to the update' $filename]
Add a New File:
1. cvs add $filename (CVS to version control the file)
2. cvs commit $filename (CVS to check in the file to the repository)
3. cvs log $filename
4. cvs diff -r tag1 tag2 $filename
Remove:
1. rm $filename (remove file from the modulo)
2. cvs remove $filename (CVS to delete the file)
3. cvs commit $filename (perform the removal from the repository
SHELL (CVS over SSH) on Linux for bash:
CVS - Concurrent Versions System
RCS - Revision Control System (RCS)
Module - particular set of files kept in CVS
Repository - Location on CVS server where modules are kept
Tag - A certain milestone in a file or module's development
Branch - A fork of the module.
SETUP CVS:
1. export CVSROOT=/cvs (add to the path)
2. cvs init (create depository)
3. cd /home/mike/cvs/project_directory (change directory to projec directory)
4. cvs import -m "Sample Program" project sample start (import project to CVS repository)
5. cvs checkout projectname (get copy of the $projectname. Can be done from Linux(ssh/pserver or Windows(through ssh using WINCVS[http://www.wincvs.org/])
Most Useful Commands:
Add/Update changes to CVS - [cvs commit -m 'Message to the update' $filename]
Add a New File:
1. cvs add $filename (CVS to version control the file)
2. cvs commit $filename (CVS to check in the file to the repository)
3. cvs log $filename
4. cvs diff -r tag1 tag2 $filename
Remove:
1. rm $filename (remove file from the modulo)
2. cvs remove $filename (CVS to delete the file)
3. cvs commit $filename (perform the removal from the repository
SHELL (CVS over SSH) on Linux for bash:
1.export CVS_RSH=SSH
2.cvs -d :ext:USERNAME@host:/cvsroot CVS_COMMAND
Tuesday, March 24, 2009
The Programatic Programmer. Book authors: Andrew Hunt and David Thomas (notes)
Programmer Goals:
1. Learn at least one new language every year.
2. Read a technical book each quarter.
3. Read nontechnical books, too.
4. Take classes.
5. Participate in local user groups.
6. Experiment with different environments.
7. Stay current
8. Get wired.
DRY - Don't Repeat Yourself.
The Law of Demeter for functions attempts to minimize coupling between modules in any given program.
Metadata - is data about data. Put Abstractions in Code, Details in Metadata.
MVC is typically taught in the context of GUI development, it is really general-purpose programming technique.
- Model. The abstract data representing the target object. The model has no direct knowledge of any views or controllers.
- View. A way to interpret the model. It describes to changes in the model and logical events from the controller.
- Controller. A way to control the view and provide the mode with new data. It publishes events to both model and the view.
The O() Notation
Is a mathematical way of dealing with approximation. Some common O() notations
Common Sense Estimation
Simple Loops:
If a simple loop runs 1 to n, then the algorithm
becomes to be O(n)-time increases linearly with n.
Examples include exhaustive searches, finding the maximum value in an array, and generating checksums.
Nested Loops:
If you nest a loop inside another, then your algorithm becomes
O(m x n), where m and n are two loops' limits. This commonly
occurs in simple sorting algorithms, such as buble sort,
where the outter loop scans each element in the array in turn,
and the inner loop works out where to place that element in the
sorted result. Such sorting algorithms tend to be O(n2)
Binary Chop:
If your algorithm halves the set of thins is considers each time
around the loop, then it is likely to be algorithmic, O(lg(n)).
A binary search of a sorted list, traversing a binary tree, and
finding the first set bit in a machine word can all be O(lg(n)
Divide and Conquer:
Algorithms that partition their input, work on the two halves
independently, and then combine the result can be O(nlg(n)). The
classic example is quicksort, which works by partitioning the
data into two halves and recursively sorting each. Although
technically O(n2), because its behavior degrades when it is fed
sorted input, the average runtime of quicksort is O(nlg(n))
Combinatoric:
Whenever algorithms start looking at the permutations of things, their
running times may get out of hand. This is because permutations involve
factorials (there are 5! = 5 x 4 x 3 x 2 x 1) = 120 permutations of the
digits from 1 to 5). Time a combinatoric algorithm for five elements: it will
take six times longer to run it for six, and 42 longer for seven. Examples
include algorithms for many of the acknowledged hard problems - the traveling salesman problem, optimally packing things into a container, partitioning a set of numbers so that each set has the same total and so on. Often, heuristics are used to reduce the running times of these types of algorithms in particular problem domains.
1. Learn at least one new language every year.
2. Read a technical book each quarter.
3. Read nontechnical books, too.
4. Take classes.
5. Participate in local user groups.
6. Experiment with different environments.
7. Stay current
8. Get wired.
DRY - Don't Repeat Yourself.
The Law of Demeter for functions attempts to minimize coupling between modules in any given program.
Metadata - is data about data. Put Abstractions in Code, Details in Metadata.
MVC is typically taught in the context of GUI development, it is really general-purpose programming technique.
- Model. The abstract data representing the target object. The model has no direct knowledge of any views or controllers.
- View. A way to interpret the model. It describes to changes in the model and logical events from the controller.
- Controller. A way to control the view and provide the mode with new data. It publishes events to both model and the view.
The O() Notation
Is a mathematical way of dealing with approximation. Some common O() notations
O(1) - Constant
(access element in array, simple statements)
O(log(n)) - Logarithmic (binary search)
O(n) - Linear (sequential search)
O(n lg(n)) - Worse the linear, but not much worse
(average runtime of quicksort, heapsort)
O(n2) - Square law (selection and insertion sorts)
O(n3) - Cubic (multiplication of 2 n x n matrices)
O(Cn) - Exponential (traveling salesman problem, set partitioning)
Common Sense Estimation
Simple Loops:
If a simple loop runs 1 to n, then the algorithm
becomes to be O(n)-time increases linearly with n.
Examples include exhaustive searches, finding the maximum value in an array, and generating checksums.
Nested Loops:
If you nest a loop inside another, then your algorithm becomes
O(m x n), where m and n are two loops' limits. This commonly
occurs in simple sorting algorithms, such as buble sort,
where the outter loop scans each element in the array in turn,
and the inner loop works out where to place that element in the
sorted result. Such sorting algorithms tend to be O(n2)
Binary Chop:
If your algorithm halves the set of thins is considers each time
around the loop, then it is likely to be algorithmic, O(lg(n)).
A binary search of a sorted list, traversing a binary tree, and
finding the first set bit in a machine word can all be O(lg(n)
Divide and Conquer:
Algorithms that partition their input, work on the two halves
independently, and then combine the result can be O(nlg(n)). The
classic example is quicksort, which works by partitioning the
data into two halves and recursively sorting each. Although
technically O(n2), because its behavior degrades when it is fed
sorted input, the average runtime of quicksort is O(nlg(n))
Combinatoric:
Whenever algorithms start looking at the permutations of things, their
running times may get out of hand. This is because permutations involve
factorials (there are 5! = 5 x 4 x 3 x 2 x 1) = 120 permutations of the
digits from 1 to 5). Time a combinatoric algorithm for five elements: it will
take six times longer to run it for six, and 42 longer for seven. Examples
include algorithms for many of the acknowledged hard problems - the traveling salesman problem, optimally packing things into a container, partitioning a set of numbers so that each set has the same total and so on. Often, heuristics are used to reduce the running times of these types of algorithms in particular problem domains.
March 24, 2009 - first post
This is my first post in the blog. I worked today (setup CVS, SUSE 10 and yast2). Walk after work for about 2 hours. I'm planning to use the blog for everything that I found interesting and useful in my life.
Note: yast2 is rpm packaging system for SUSE10.
Note: yast2 is rpm packaging system for SUSE10.
Subscribe to:
Posts (Atom)