Skip to content

Instantly share code, notes, and snippets.

@KevinJones
KevinJones / cpp-error-handling.md
Created October 7, 2024 17:27
C++ Error Handling

C++ Error Handling

Written by Kevin Jones, 2024-10-07. Dedicated to the public domain, CC0, no rights reserved. Find me on GitHub or BlueSky.

How should we think about errors?

  • Every program will have bugs, every program will run into unlikelysituations. Error handling makes taking repsonsibility for protecting yourself and others from this kind of problems problems. ("Defensive programming", akin to defensive driving.)
  • When does the error happen: compile time or runtime?
  • How frequently will the error conditions happen: "should never", "not commonly", or "quite often"?
  • In what context is the error occurring: your library, somebody else's library, or your application?
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
~/D/P/c/puma (master) $ cd ~/Desktop/
~/Desktop $ ls
temp.js
~/Desktop $ node temp.js
8
~/Desktop $ gjslint temp.js
----- FILE : /home/kevin/Desktop/temp.js -----
Line 1, E:0002: Missing space after ","
@KevinJones
KevinJones / fix_chrome_icon.sh
Last active August 29, 2015 14:04
elementary OS Luna: Fix blurry Chrome dock icon
# If your dock icon for Chrome is blurry in elementary OS Luna, this well help you fix it.
# This will create symbolic links for each of the icon sizes in the /usr/share/icons/elementary/apps directory.
# Log out and log back in afterwards to see the changes.
function make_link {
if [ "$1" ]
then
SIZE=$1; sudo ln -s /opt/google/chrome/product_logo_$SIZE.png /usr/share/icons/elementary/apps/$SIZE/google-chrome.png
fi
}
@KevinJones
KevinJones / gist:11264481
Created April 24, 2014 18:25
Multiple Singletons Example
// Three parts:
// 1. an enum with N values (or N+1 if you include a "None")
// 2. N enumerated singleton instances implementing a common interface. These provide information associated with each enum value in one place.
// 3. a static class allowing callers to access each enumerated singleton instance by passing in the corresponding enum value, creating it if necessary.
// Part 1
public enum Biome
{
Desert = 1,
Snow = 1 << 1,
// a global function; no need to expose this in a header file
void internalDoSomething()
{
// put your function here.
}
// note that if you were using C++ or Objective-C++ you'd need to put this in an extern closure, like so:
extern "C"
{
@KevinJones
KevinJones / CartesianProductSelectManyExample.cs
Created February 13, 2014 19:32
C# SelectMany Example - Cartesian Product
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class CartesianProductSelectManyExample
{
public static void Main(string[] args)
{
var abcArray = new string[]{"a", "b", "c"};
void Update()
{
// attach to camera
if (Input.GetMouseButtonDown(0)) {
var ray = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
Vector3 v = hit.point;
// instantiate the "ping" transform at v