Skip to content

Instantly share code, notes, and snippets.

View kjelloh's full-sized avatar

kjelloh

View GitHub Profile
@kjelloh
kjelloh / LinuxInstallVSCode.md
Last active July 28, 2016 19:10
Visual Studio COde Linux Install/Update/Uninstall scripts
@kjelloh
kjelloh / install_vscode
Created July 28, 2016 18:25
A Linux Install Visual Studio Code script
#From https://gist.github.com/pomber/db44098f3413d5213aec
#160728: https://code.visualstudio.com/Docs/?dv=linux64
#160728: Link to zip-file https://go.microsoft.com/fwlink/?LinkID=620884
if [ -d /opt/vscode ]
then
echo Previous installation exists. Run update_vscode
else
curl -L https://go.microsoft.com/fwlink/?LinkID=620884 > /tmp/vscode.zip
sudo unzip -qq /tmp/vscode.zip -d /tmp
echo Unzipped to /tmp/vscode*
@kjelloh
kjelloh / Cpp_Core_Guidline_R37_Herb_Sutter_CppCon2015_Example.cpp
Last active August 15, 2016 17:13
Elaboration on Herb Sutter Core Guidlines example for Smart Pointers (See 57:45 into https://youtu.be/hEx5DNLWGgA)
//
// main.cpp
// MySharedPtrPlayGround
//
// Created by Kjell-Olov Högdahl on 2016-08-15.
// Copyright © 2016 Kjell-Olov Högdahl. All rights reserved.
//
#include <iostream>
#include <memory> // shared_ptr
@kjelloh
kjelloh / Dont_inherit_from_std_vector.md
Created August 18, 2016 20:21
When C++ don't do what you expect. Or, Don't inherit from std::vector?

C++ don't always do what you think it should do?

"So you are brave enough to inherit from std::vector?" Paul looks curiously at me and I can't tell if he is joking or not. I had just told him about this program and how it does not work.

Quiz: Why does this program output a strange number of zeroes?

//
//  main.cpp
//  ibi
@kjelloh
kjelloh / refernce_to_reference_implies_value_assign.cpp
Last active May 16, 2020 03:00
C++ - Can't pass reference to reference (value assign is implied)
struct foo {
foo& operator=(const foo& other) = delete; // foo is not copy-assignable
};
void bar() {
foo f1;
foo& r1 = f1; // Ok. r1 is reference to f1.
foo& r2 = r1; // ok. r2 is refernce to r1 which is semanticly the value f1.
r2 = r1; // Error. Semantics implies value assign (although both sides are references) and foo instance f1 is not assignable.
//
// main.cpp
// MydecltypeMetaFunctions
//
// Created by Kjell-Olov Högdahl on 2016-12-10.
//
/*
Program Output:
@kjelloh
kjelloh / Yuval_Hariri_Sapien_KoH_Notes.txt
Created January 26, 2017 16:50
My short notes to reading of ISBN 978-91-27-14039-4 “Sapiens” “Svensk utgåva 2014
"What are the most compelling points made by Yuval Harari in his book “Sapiens” (which I read in Swedish)
References to ISBN 978-91-27-14039-4 “Sapiens” “Svensk utgåva 2014, Natur & Kultur, Stockholm” (Stockholms Stadsbiblioteken Medborgarplatsen)
1) The human ability to cooperate effectively and flexibly with strangers centered round a “story” (chapter “Legenden om Peugeot”)
2) Made-up stories resulting in different norms and values in experiencing the “same” reality (“En dag i Adam och Evas liv” p51)
3) Prehistoric man probably caused mass extinction of gracing animals in Australia and north america (“Skyldig!” p73…)
4) Man entered agricultural age without getting more intelligent (“Historiens största bluff” p85).
5) Man became “trapped” into agricultural society by the very plants they grew (“Historiens största bluff” p85)
6) Small seemingly good enhancements led to man being trapped in agricultural society having to work more for less nutritious food (“Lyxfällan” p89))
@kjelloh
kjelloh / pi_estimation_plain_imperative.cpp
Created March 12, 2017 17:23
A PI Estimation example using plain C++ imperative abstractions
//
// Created by Kjell-Olov Högdahl on 2017-03-08.
// This work is licensed under
// Creative Commons Attribution 4.0 International License.
// https://creativecommons.org/licenses/by/4.0/
//
#include <iostream>
#include <cmath> // std::pow
#include <random> // random_device, std::mt19937, uniform_int_distribution
@kjelloh
kjelloh / pi_estimate_generate_n.cpp
Last active March 12, 2017 18:23
An Pi estimation example using std::generate_n
//
// Created by Kjell-Olov Högdahl on 2017-03-08.
// This work is licensed under
// Creative Commons Attribution 4.0 International License.
// https://creativecommons.org/licenses/by/4.0/
//
#include <iostream>
#include <cmath> // std::pow
#include <random> // random_device, std::mt19937, uniform_int_distribution
@kjelloh
kjelloh / pi_estimate_transform.cpp
Created March 12, 2017 17:56
A Pi Estimation example using std::transform
//
// Created by Kjell-Olov Högdahl on 2017-03-08.
// This work is licensed under
// Creative Commons Attribution 4.0 International License.
// https://creativecommons.org/licenses/by/4.0/
//
#include <iostream>
#include <cmath> // std::pow
#include <random> // random_device, std::mt19937, uniform_int_distribution