Thursday, April 23, 2009

Oracle setting timestamp format and query

alter session set NLS_DATE_FORMAT='DD-MM-YYYY HH24:MI:SS'

select * from table where date > to_date('2009-04-01','yyyy-mm-dd');

Saturday, April 11, 2009

Problems with macbook

I started having this problem with my macbook and apparently I am not the only one
MacBook Crack

How to run a process even when your session ends and exits

Process :
-run process (from zshell)

-Ctrl-Z (to suspend)

-disown

-kill -CONT

Sunday, April 05, 2009

WalkScore of a Place

Get Walkscore of your place is a pretty handy tool to find out how accessible is your place to the nearby restaurants, gorceries, banks etc.

Wednesday, March 25, 2009

Write a binary stream (cannot output to a string)

std::string s(record.data.buf(), record.data.size());
ofstream file1;
file1.open ("/tmp/kalyan",ios::binary);
file1.write(bytebuffer, size);
file1.close();

Sunday, February 15, 2009

Poker Basics

Frpm "pokerbasics.com"

Saturday, February 14, 2009

Better terminal for Mac

Iterm is pretty good if you are not happy with the mac osx built in terminal

Saturday, January 31, 2009

Prefix and Postfix operators in C++?

Thanks to stackoverflow "JProgrammer"

"Taking a leaf from Scott Meyers, More Effective c++ Item 6: Distinguish between prefix and postfix forms of increment and decrement operations.

The prefix version is always preferred over the postfix in regards to objects, especially in regards to iterators.

The reason for this if you look at the call pattern of the operators.

// Prefix
Integer& Integer::operator++()
{
*this += 1;
return *this;
}

// Postfix
const Integer Integer::operator++(int)
{
Integer oldValue = *this;
++(*this);
return oldValue;
}

Looking at this example it is easy to see how the prefix operator will always be more efficient than the postfix. Because of the need for a temporary object in the use of the postfix.

This is why when you see examples using iterators they always use the prefix version.

But as you point out for int's there is effectively no difference because of compiler optimisation that can take place.
"

Wednesday, January 21, 2009

XML Streaming

// Creates a new reader (potentially recycled).
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader reader = factory.createXMLStreamReader(inputStream);

while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
switch (reader.next()) {
case XMLStreamConstants.START_ELEMENT:
if (reader.getLocalName().equals("Time")) {
// Reads primitive types (int) attributes directly (no memory allocation).
time.hour = reader.getAttributeValue("hour").toInt();
time.minute = reader.getAttributeValue("minute").toInt();
time.second = reader.getAttributeValue("second").toInt();
}
...
break;
}
}

XML Streaming

// Creates a new reader (potentially recycled).
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader reader = factory.createXMLStreamReader(inputStream);

while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
switch (reader.next()) {
case XMLStreamConstants.START_ELEMENT:
if (reader.getLocalName().equals("Time")) {
// Reads primitive types (int) attributes directly (no memory allocation).
time.hour = reader.getAttributeValue("hour").toInt();
time.minute = reader.getAttributeValue("minute").toInt();
time.second = reader.getAttributeValue("second").toInt();
}
...
break;
}
}

Wednesday, January 14, 2009

Setting up a multiple display with MAC and linux

This is my personal preferences can change:

1. Run Synergy server on linux
http://synergy2.sourceforge.net/

2. Run synergyc client on mac
http://sourceforge.net/projects/synergykm

3. Edit .synergy.conf on your home directory

section: screens
linux desktop:
mac client:
end
section: links
mac client:
right = linux desktop
linux desktop:
left = mac client
end

4. On you mac terminal i do this
alias command="killall -c ssh; ssh -nf -L 24800:localhost:24800 -L 5917:localhost:5901 -L 5918:localhost:5902 linuxbox -- 'sleep 999999999'"

There could be a better method here

5. For connecting the macbook to another monitor use this
mini dvi to vga adapter
http://store.apple.com/us/product/M9320G/A

You might have to restart your mac book here.

Vola you are done.

Sunday, December 28, 2008

Container Summary Complexity from StrousStroup

Vector

[] - const
List Operations - O(n)+
Iterators - Random

List

List operation - const
Front operations - const
Back operations - const
Iterators - Bi

Dequeue
[] - const
List operations - O(n)
Front operations - const
Back operations - const
Iterators - Ran

List operations include
- Insert
- erase
- clear

Saturday, December 27, 2008

StrousStroup Container Design : Review

Notes from Container Design Chapter in StrousStroup

- What is a container?
A Container is an object that holds other objects

- What is an iterator?
Iterator is a means of traversing objects in the container (Used to navigate containers)

- Important member of a Container for iterator
iterator begin() //points to the first element
const_iterator begin() const

iterator end() //points to one-past-last element
const_iterator end() const

reverse_iterator rbegin()
const_reverse_iterator ebegin() const;

reverse_iterator end()
const_reverse_iterator rend() const;

- Element access in a vector

reference operator[] (size_type n); //unchecked access

reference at (size_type n); //checked access

- Passing vectors

f1(vector &)
f2(const vector &)

vector v(1000);
f1(v) //pass reference

- reserve in vector allocates space in advance

- capacity() gives the current numbers of reserved memory slots

- size() gives the current number of elements

- Pointer cannot address a unit of memory smaller than a byte



- Link
Vector Code

Wednesday, December 24, 2008

C++ Abstract Base Classes

#include "string"
#include "sstream"
using namespace std;

class AbstractStatic {

public:
static std::string constructKey(int a, int b) {

std::ostringstream ostr;

ostr «« a «« ":" «« b «« endl;
return ostr.str();
}
virtual std::string makekey(int a, int b) = 0;
virtual ~AbstractStatic();

};

class AbstractConcrete: public AbstractStatic
{
public:
std::string makeKey(int a, int b) {
std::ostringstream ostr;

ostr «« a «« "+" «« b «« endl;
return ostr.str();
}

};

void foo(AbstractStatic* a) {

cout «« "In function foo" «« endl;
}

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

AbstractStatic* as;
AbstractStatic as; //this is an erro and foo(as) is also an error
string a = AbstractConcrete::constructKey(1,2);
foo(as);
cout «« a «« endl;
return 0;
}

VNC Client for MAC

Stumbled upon this sourceforge project for VNC Client for MAC

Chicken for VNC

Saturday, December 20, 2008

STL MAP

From deez.info

"

Let’s say you have two STL std::maps with identical types, and you want to copy all the elements from one to the other. The easiest way to do this is to use map::insert():

typedef std::map map_t;

map_t map1;
map_t map2;

// Copy all elements from map1 to map2
map2.insert(map1.begin(), map1.end());

Alternatively, you could use the STL std::copy algorithm:

// Copy all elements from map1 to map2.
std::copy(map1.begin(), map1.end(), std::inserter(map2, map2.begin()));

Both methods’ performance should be an amortized O(n) because they insert records in sorted order and use the hinting form of map::insert.

Note that because both methods ultimately call map::insert they will not overwrite a preexisting key’s associated value. In other words, if map1 has the value V1 associated with key K and map2 the value V2 associated with the same key K, V2 will remain in map2 after the copy operation.

Let’s say you want to perform the copy but have map1’s values overwrite map2’s for identical keys. The first way to solve this problem that entered my mind was to write my own OutputIterator which performs an overwriting assignment and pass it to std::copy. However, there’s a far simpler approach. You can copy map2’s values into map1, relying on the fact that map2’s values won’t overwrite map1’s, and then swap the results:

map1.insert(map2.begin(), map2.end());
map2.swap(map1);

Thanks, Sam, for helping me figure all this out.
"

Saturday, November 22, 2008