Thursday, 10 September 2015

Advanced Go: Maps

A map maps keys to values.
Maps must be created with make (not new) before use; the nil map is empty and cannot be assigned to.


Map literals

Map literals are like struct literals, but the keys are required.


If the top-level type is just a type name, you can omit it from the elements of the literal.



Do like it, if you found it usefull.

Wednesday, 9 September 2015

How to fix: Open or access your modem/router

It is very simple.

Step1: connect with your modem/router through Lan/Wifi(if available)

Step2: open modem url 192.168.1.1 in some rare modem 192.168.0.1

Step3: username = admin, password = admin or check your modem for username and password.

And you are done. So simple Right!! If you reading this and found helpful, Go crazy!!

Do like it, if you found it useful.

Monday, 7 September 2015

How to fix: Slow internet surfing but having great gaming experince

Since past week, I was suffering from slow or almost no internet because i set up NAT setting for ps4 call of duty advanced warefare. (If you are looking for NAT settings go to portforward site).

"Anything worse then no internet is slow internet!!" -- Anon

If above is your case, you just need to disable the NAT settings after gaming and vice verse before starting gaming. Yaa it is bad and painful. But still worth it because we could be a better player with NAT settings. My Multiplayer gameplay 100% improved after NAT setting.

See pic for more clarification..... Just Click the disable button for all and you are done...

Sunday, 6 September 2015

Advanced Go: Range

Range

The range form of the for loop iterates over a slice or map.


Range continued

You can skip the index or value by assigning to _.
If you only want the index, drop the ", value" entirely.



Do like it, if you found it usefull.

Saturday, 5 September 2015

Advanced Go: Slices continued

Adding elements to a slice

It is common to append new elements to a slice, and so Go provides a built-in appendfunction.
func append(s []T, vs ...T) []T
The first parameter s of append is a slice of type T, and the rest are T values to append to the slice.
The resulting value of append is a slice containing all the elements of the original slice plus the provided values.
If the backing array of s is too small to fit all the given values a bigger array will be allocated. The returned slice will point to the newly allocated array.
Do like it, if you found it usefull.

Monday, 31 August 2015

Advanced Go: Slices continued...

Making slices

Slices are created with the make function. It works by allocating a zeroed array and returning a slice that refers to that array:
a := make([]int, 5)  // len(a)=5
To specify a capacity, pass a third argument to make:
b := make([]int, 0, 5) // len(b)=0, cap(b)=5

b = b[:cap(b)] // len(b)=5, cap(b)=5
b = b[1:]      // len(b)=4, cap(b)=4




Nil slices

The zero value of a slice is nil.
A nil slice has a length and capacity of 0.


Do comment, if it worked/Not worked for you.

Sunday, 30 August 2015

Advanced Go: Slices

A slice points to an array of values and also includes a length.

[]T is a slice with elements of type T.


Slicing slices

Slices can be re-sliced, creating a new slice value that points to the same array.
The expression
s[lo:hi]
evaluates to a slice of the elements from lo through hi-1, inclusive. Thus
s[lo:lo]
is empty and
s[lo:lo+1]
has one element.

Do comment, if it worked/Not worked for you.

Saturday, 29 August 2015

Advanced Go: Array

The type [n]T is an array of n values of type T.

The expression
var a [10]int
declares a variable a as an array of ten integers.
An array's length is part of its type, so arrays cannot be resized. This seems limiting, but don't worry; Go provides a convenient way of working with arrays.


Do comment, if it worked/Not worked for you.

Friday, 28 August 2015

Advanced Go: Struct

A struct is a collection of fields.

(And a type declaration does what you'd expect.)


Struct Fields

Struct fields are accessed using a dot.

Pointers to structs

Struct fields can be accessed through a struct pointer.
The indirection through the pointer is transparent.

Struct Literals

A struct literal denotes a newly allocated struct value by listing the values of its fields.
You can list just a subset of fields by using the Name: syntax. (And the order of named fields is irrelevant.)
The special prefix & returns a pointer to the struct value.


Do comment, if it worked/Not worked for you.

Thursday, 27 August 2015

Advanced Go: Pointers

Go has pointers. A pointer holds the memory address of a variable.

The type *T is a pointer to a T value. Its zero value is nil.
var p *int
The & operator generates a pointer to its operand.
i := 42
p = &i
The * operator denotes the pointer's underlying value.
fmt.Println(*p) // read i through the pointer p
*p = 21         // set i through the pointer p
This is known as "dereferencing" or "indirecting".
Unlike C, Go has no pointer arithmetic.



Do comment, if it worked/Not worked for you.

Sunday, 23 August 2015

Basic Go: Defer

A defer statement defers the execution of a function until the surrounding function returns.

The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.


Stacking defers

Deferred function calls are pushed onto a stack. When a function returns, its deferred calls are executed in last-in-first-out order.


Do comment, if it worked/Not worked for you.

Saturday, 22 August 2015

Basic Go: Switch

You probably knew what switch was going to look like.

A case body breaks automatically, unless it ends with a fallthrough statement.


Switch evaluation order

Switch cases evaluate cases from top to bottom, stopping when a case succeeds.
(For example,
switch i {
case 0:
case f():
}
does not call f if i==0.)
Note: Time in the Go playground always appears to start at 2009-11-10 23:00:00 UTC, a value whose significance is left as an exercise for the reader.


Switch with no condition

Switch without a condition is the same as switch true.
This construct can be a clean way to write long if-then-else chains.

Do comment, if it worked/Not worked for you.

Friday, 21 August 2015

Basic Go: For loop

Go has only one looping construct, the for loop.
The basic for loop looks as it does in C or Java, except that the ( ) are gone (they are not even optional) and the { } are required.


As in C or Java, you can leave the pre and post statements empty.

At that point you can drop the semicolons: C's while is spelled for in Go.


Do comment, if it worked/Not worked for you.

Basic Go: If statement

The if statement looks as it does in C or Java, except that the ( ) are gone and the{ } are required.


Like for, the if statement can start with a short statement to execute before the condition.
Variables declared by the statement are only in scope until the end of the if.
(Try using v in the last return statement.)


If and else

Variables declared inside an if short statement are also available inside any of theelse blocks.



Do comment, if it worked/Not worked for you.

Thursday, 20 August 2015

Basic Go: Constant

Constants

Constants are declared like variables, but with the const keyword.
Constants can be character, string, boolean, or numeric values.
Constants cannot be declared using the := syntax.


Numeric Constants

Numeric constants are high-precision values.
An untyped constant takes the type needed by its context.
Try printing needInt(Big) too.


Do comment, if it worked/Not worked for you.

Wednesday, 19 August 2015

Basic Go: Type, Values, Inference and Conversions

Types

Go's basic types are
bool

string

int  int8  int16  int32  int64
uint uint8 uint16 uint32 uint64 uintptr

byte // alias for uint8

rune // alias for int32
    // represents a Unicode code point

float32 float64

complex64 complex128
The example shows variables of several types, and also that variable declarations may be "factored" into blocks, as with import statements.

Type Values

Variables declared without an explicit initial value are given their zero value.
The zero value is:
  • 0 for numeric types,
  • false the boolean type, and
  • "" (the empty string) for strings.

Type conversions

The expression T(v) converts the value v to the type T.
Some numeric conversions:
var i int = 42
var f float64 = float64(i)
var u uint = uint(f)
Or, put more simply:
i := 42
f := float64(i)
u := uint(f)
Unlike in C, in Go assignment between items of different type requires an explicit conversion. Try removing the float64 or int conversions in the example and see what happens.

Inference

When declaring a variable without specifying its type (using var without a type or the:= syntax), the variable's type is inferred from the value on the right hand side.
When the right hand side of the declaration is typed, the new variable is of that same type:
var i int
j := i // j is an int
But when the right hand side contains an untyped numeric constant, the new variable may be an int, float64, or complex128 depending on the precision of the constant:
i := 42           // int
f := 3.142        // float64
g := 0.867 + 0.5i // complex128
Try changing the initial value of v in the example code and observe how its type is affected.

Do comment, if it worked/Not worked for you.