Skip to content

Instantly share code, notes, and snippets.

View Adobe-Android's full-sized avatar

David Brown Adobe-Android

View GitHub Profile
@Adobe-Android
Adobe-Android / calc.cpp
Last active December 14, 2022 17:26
A calculator exercise in C++ using enum classes/scoped enums, structs, and member functions
#include <iostream>
enum class Operation { Add, Subtract, Multiply, Divide };
struct Calculator {
Operation op;
Calculator(Operation operation) { op = operation; }
int calculate(int a, int b) {
switch (op) {
@Adobe-Android
Adobe-Android / cpp_compile.ps1
Last active September 29, 2019 17:44
PowerShell script collection (built with Windows 10 and Linux (pengwin - Debian-based) in mind on PowerShell Core 7.0.0-preview.4
#!/usr/bin/pwsh-preview
# Setting default values for some variables
$configVersion = ""
$preferredCompiler = ""
$cppStandard = ""
$additionalFlags = ""
$currentDir = (Get-Item -Path ".\").FullName
$configPath = "$currentDir/cpp_config.xml"
$PSVersion = "PowerShell " + $PSVersionTable.PSEdition + " version: " + $PSVersionTable.PSVersion
@Adobe-Android
Adobe-Android / int_fast.cpp
Last active September 17, 2020 17:22
A comparison of int_fast and int_least at various guaranteed sizes (will vary based on system architecture and whether the program is 32 or 64-bit)
#include <iostream>
int main() {
// Optimizes for speed over memory use.
// On modern machines, int_fast16_t will often instead be 32-bit, consuming 4 bytes like
// int_fast32_t. This is actually better for performance.
std::cout << sizeof(int_fast16_t) << '\n';
std::cout << sizeof(int_fast32_t) << '\n';
std::cout << sizeof(int_fast64_t) << '\n';
@Adobe-Android
Adobe-Android / convert_stdstring_to_char_array.cpp
Last active September 17, 2020 18:10
A small modern C++ example converting a std::string to a c-style string (character array).
#include <iostream>
#include <string>
void print_to_screen(const char* char_array) { std::cout << char_array << '\n'; }
int main() {
std::string std_str{"Hello, World!\n"};
const char* char_array{std_str.c_str()};
print_to_screen(char_array);
@Adobe-Android
Adobe-Android / get_i2C_address.ino
Last active June 1, 2019 20:38
My Arduino Software Collection
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(115200);
Serial.println("\nI2C Scanner");
}
void loop()
@Adobe-Android
Adobe-Android / .zshrc
Created April 15, 2019 04:53
Zshrc file
# Path to your oh-my-zsh installation.
export ZSH=/home/vm/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
# POWERLEVEL9K_MODE='nerdfont-complete'
# ZSH_THEME="powerlevel9k/powerlevel9k"
ZSH_THEME="robbyrussell"
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
@Adobe-Android
Adobe-Android / node.js
Created April 15, 2019 04:30
Some useful node.js commands
#!/usr/bin/env node
const {node: nodeVersion, v8: v8Version, openssl: sslVersion, unicode: uniVersion} = process.versions;
console.log("Node.js version:", nodeVersion);
console.log("V8 version:", v8Version);
console.log("OpenSSL version:", sslVersion);
console.log("Unicode support:", uniVersion);
// console.log(process.versions);
@Adobe-Android
Adobe-Android / Interface.cs
Last active September 17, 2020 17:48
Employee interface and implementation (in one file for convenience)
using System;
interface IEmployee
{
string Id { get; set; }
string FullName { get; set; }
string Email { get; set; }
string Phone { get; set; }
string Company { get; }
}
@Adobe-Android
Adobe-Android / read_file.c
Last active February 26, 2019 00:33
Read in a file and handle errors and write to a file and handle errors
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define bufSize 1024
int main(int argc, char const *argv[])
{
FILE *in;
char buf[bufSize];
@Adobe-Android
Adobe-Android / str_reverse.c
Created February 10, 2019 01:52
C string reversal
int main()
{
char s[20], r[20];
int begin, end, count = 0;
printf("Input a string\n");
scanf("%s", s);
// Calculating string length
while (s[count] != '\0')