This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <codecvt> | |
#include <iostream> | |
#include <locale> | |
#include <string> | |
int main() | |
{ | |
using namespace std::literals::string_literals; | |
std::string s = "hello world"s; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chrono> | |
#include <iostream> | |
int main() | |
{ | |
using namespace std::literals::chrono_literals; | |
std::chrono::nanoseconds t1 = 600ns; | |
std::chrono::microseconds t2 = 42us; | |
std::chrono::milliseconds t3 = 51ms; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
long double operator"" _km(long double val) | |
{ | |
return val * 1000.0; | |
} | |
long double operator"" _mi(long double val) | |
{ | |
return val * 1609.344; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template< char FIRST, char... REST > struct binary | |
{ | |
static_assert( FIRST == '0' || FIRST == '1', "invalid binary digit" ) ; | |
enum { value = ( ( FIRST - '0' ) << sizeof...(REST) ) + binary<REST...>::value } ; | |
}; | |
template<> struct binary<'0'> { enum { value = 0 } ; }; | |
template<> struct binary<'1'> { enum { value = 1 } ; }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// :show start | |
func Add(a, b int) int { | |
return a + b | |
} | |
func AddAndMultiply(a, b int) (int, int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// :collection Essential Go | |
package main | |
import ( | |
"fmt" | |
) | |
// :show start | |
// addCheckOverflow adds two int16 numbers and additionally | |
// returns true if the result overflowed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
let newArr = arr.slice(0, 2); | |
console.log("slice(0,2) :", newArr) | |
newArr = arr.slice(8); | |
console.log("slice(8) :", newArr) | |
newArr = arr.slice(5, -1); | |
console.log("slice(5, -1):", newArr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
) | |
func main() { | |
// :show start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// :collection Essential Go | |
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"os" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"archive/zip" | |
"fmt" | |
"io" | |
"log" | |
"os" | |
"path/filepath" | |
) |