Tutorial by Examples: c

import "reflect" value := reflect.ValueOf(4) // Interface returns an interface{}-typed value, which can be type-asserted value.Interface().(int) // 4 // Type gets the reflect.Type, which contains runtime type information about // this value value.Type().Name() // int value.SetInt(5)...
import "reflect" type S struct { A int b string } func (s *S) String() { return s.b } s := &S{ A: 5, b: "example", } indirect := reflect.ValueOf(s) // effectively a pointer to an S value := indirect.Elem() // this is addressable, since we've derefed a point...
import "reflect" s := []int{1, 2, 3} value := reflect.ValueOf(s) value.Len() // 3 value.Index(0).Interface() // 1 value.Type().Kind() // reflect.Slice value.Type().Elem().Name() // int value.Index(1).CanAddr() // true -- slice elements are addressable value....
import "reflect" // this is effectively a pointer dereference x := 5 ptr := reflect.ValueOf(&x) ptr.Type().Name() // *int ptr.Type().Kind() // reflect.Ptr ptr.Interface() // [pointer to x] ptr.Set(4) // panic value := ptr.Elem() // this is a deref value.Type().Name() // int...
Package can have init methods which are run only once before main. package usefull func init() { // init code } If you just want to run the package initialization without referencing anything from it use the following import expression. import _ "usefull"
In go it can sometimes be useful to know which underlying type you have been passed. This can be done with a type switch. This assumes we have two structs: type Rembrandt struct{} func (r Rembrandt) Paint() {} type Picasso struct{} func (r Picasso) Paint() {} That implement the Painter ...
In C# (and .NET) a string is represented by class System.String. The string keyword is an alias for this class. The System.String class is immutable, i.e once created its state cannot be altered. So all the operations you perform on a string like Substring, Remove, Replace, concatenation using + o...
You can install Json.Net into your Visual Studio Project in 1 of 2 ways. Install Json.Net using the Package Manager Console. Open the Package Manager Console window in Visual Studio either by typing package manager console in the Quick Launch box and selecting it or by clicking View -> O...
This is the flavor of markdown that's used by Stack Overflow and other Stack Exchange sites. When you answer a question or add documentation you use this markdown. This answer is made out of SO markdown See Official Documentation The main things that SO markdown adds are under "Stack Exchan...
The goal is to generate the following XML document: <FruitBasket xmlns="http://www.fruitauthority.fake"> <Fruit ID="F0001"> <FruitName>Banana</FruitName> <FruitColor>Yellow</FruitColor> </Fruit> <Fruit ID="F000...
Introduction Classes that implement this interface no longer support __sleep() and __wakeup(). The method serialize is called whenever an instance needs to be serialized. This does not invoke __destruct() or has any other side effect unless programmed inside the method. When the data is unseriali...
The ROUND function rounds a value. The number of decimal places to round to is specified by a positive value in the num_digits parameter. A negative value for the num_digits will round the integer portion of the value left of the decimal point, e.g. to the nearest 10 (for -1) or to the nearest 1000 ...
The excel formula TRUNC is used to truncate a number to a given number of decimal places, specified by the optional num_digits parameter. If this parameter is defined as a negative value it will truncate the integer portion of the value. If the parameter is omitted then the default value is 0 which ...
The Excel function MROUND is used to round a number to an interval other than a power of 10. These examples show MROUND to the nearest quarter and to the nearest even number. Starting withMROUND(b,0.25)MROUND(b,2)23.9319521124.00242.7931353882.75221.9390306422.002213.7419373913.751416.7704741216.7...
You need to find out the IP address of the container running in the host so you can, for example, connect to the web server running in it. docker-machine is what is used on MacOSX and Windows. Firstly, list your machines: $ docker-machine ls NAME ACTIVE DRIVER STATE URL ...
Select Case can be used when many different conditions are possible. The conditions are checked from top to bottom and only the first case that match will be executed. Sub TestCase() Dim MyVar As String Select Case MyVar 'We Select the Variable MyVar to Work with Case "...
Helpful when you want to grab a copy of a production database to play around with locally. mongodump --host some-mongo-host.com:1234 -d DATABASE_NAME -u DATABASE_USER -p DATABASE_PASSWORD This will create a local dump directory; within that directory you'll see a directory with your DATABASE_NAME...
While your Meteor app is running locally: meteor mongo --url
Set the MONGO_URL environment variable before starting your local Meteor app. Linux/MacOS Example: MONGO_URL="mongodb://some-mongo-host.com:1234/mydatabase" meteor or export MONGO_URL="mongodb://some-mongo-host.com:1234/mydatabase" meteor Windows Example Note: don't u...
A dotfile is a file whose names begin with a .. These are normally hidden by ls and not listed unless requested. For example the following output of ls: $ ls bin pki The -a or --all option will list all files, including dotfiles. $ ls -a . .ansible .bash_logout .bashrc .lesshst ...

Page 141 of 826