Skip to content

Instantly share code, notes, and snippets.

@kkabdol
kkabdol / exercise-fibonacci-closure.go
Created April 14, 2016 08:38
go language exercise
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a, b := 0, 1
return func() int {
ret := a
@kkabdol
kkabdol / exercise-error.go
Created April 15, 2016 09:41
go language exercise
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
@kkabdol
kkabdol / exercise-reader.go
Created April 15, 2016 10:16
go language exercise
package main
import (
"golang.org/x/tour/reader"
"io"
)
type MyReader struct{}
// TODO: Add a Read([]byte) (int, error) method to MyReader.
package main
import (
"golang.org/x/tour/tree"
"fmt"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
@kkabdol
kkabdol / exercise-web-crawler.go
Created April 22, 2016 02:11
go language exercise
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
@kkabdol
kkabdol / pointer_vs_references.cpp
Last active May 18, 2016 09:28
Pointer versus References example
string s1("Nancy");
string s2("Clancy");
string& rs = s1; // rs refers to s1
string* ps = &s1; // ps points to s1
rs = s2; // rs still refers to s1, but s1's value is now "Clancy"
ps = &s2 // ps now points to s2; s1 is unchanged
@kkabdol
kkabdol / passbyreference_chararray.cpp
Last active June 23, 2016 02:27
Pass By Reference - Char Array
#include <iostream>
using namespace std;
void print( const char ( &UniqueId )[ 40 ] )
{
cout << UniqueId << endl;
}
int main()
@kkabdol
kkabdol / explicit_keyword.cpp
Created June 23, 2016 15:16
explicit keyword
template<class T>
class Array {
public:
...
explicit Array(int Size);
...
};
Array<int> a(10);
Array<int> b(10);
@kkabdol
kkabdol / const_int_vs_int_const.cpp
Last active July 5, 2016 02:38
const int vs int const
#include <iostream>
using namespace std;
int main() {
int a;
int * mutable_pointer_to_mutable_int;
int const * mutable_pointer_to_constant_int;
const int * mutable_pointer_to_constant_int2;
@kkabdol
kkabdol / delete_null_pointer.cpp
Last active July 7, 2016 07:56
delete null pointers
AClass::~AClass()
{
//if( mObj != null ) // no need to check
//{
delete mObj;
//}
}