Skip to content

Instantly share code, notes, and snippets.

View kjk's full-sized avatar

Krzysztof Kowalczyk kjk

View GitHub Profile
#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;
#include <iostream>
long double operator"" _km(long double val)
{
return val * 1000.0;
}
long double operator"" _mi(long double val)
{
return val * 1609.344;
#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 } ; };
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)
#include <iostream>
int main()
{
int x = 1;
if (x > 0) {
std::cout << "x (" << x << ") is greater than zero\n";
}
}
@kjk
kjk / github graphql.txt
Created June 18, 2020 02:03
github graphql examples (made with https://codeeval.dev)
{
viewer {
gists(first: 10) {
nodes {
id
isPublic
isFork
name
pushedAt
createdAt
#include <iostream>
constexpr long long factorial(int n)
{
long long result = 1;
for (int i = 1; i <= n; ++i) {
result *= i;
}
return result;
}
#include <iostream>
constexpr long long factorial(long long n)
{
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
#include <iostream>
constexpr long long factorial(long long n)
{
return (n == 0) ? 1 : n * factorial(n - 1);
}
int main()
{
char test[factorial(3)];
#include <iostream>
#include <type_traits>
template<long long n>
struct factorial :
std::integral_constant<long long, n * factorial<n - 1>::value> {};
template<>
struct factorial<0> :
std::integral_constant<long long, 1> {};