Skip to content

Instantly share code, notes, and snippets.

@nramsbottom
nramsbottom / parking.ino
Last active July 18, 2019 21:09
HC-SR04 Parking Sensor
#include <NewPing.h> // https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
#include <toneAC.h> // https://github.com/teckel12/arduino-toneac
#define SONAR_TRIGGER 3
#define SONAR_ECHO 2
#define SONAR_MAX_DISTANCE 200 // cm
#define TONE_FREQ 1000 // hz
NewPing sonar(SONAR_TRIGGER, SONAR_ECHO, SONAR_MAX_DISTANCE);
@nramsbottom
nramsbottom / MD5HashFile.cs
Last active August 11, 2018 17:56
Helper function for producing hashes of files.
static string MD5HashFile(string path, int readBufferSize = 0xFFFF)
{
if (path == null) throw new ArgumentNullException(nameof(path));
if (readBufferSize < 1) throw new ArgumentOutOfRangeException(nameof(readBufferSize), "The read buffer size cannot be less than 1");
var readBuffer = new byte[readBufferSize];
using (var stream = File.OpenRead(path))
using (var hasher = MD5.Create())
{
@nramsbottom
nramsbottom / temperature_dht11.ino
Created July 15, 2018 16:20
Digital Temperature Sensor using DHT11 sensor of a 128x64 OLED display (SSD1306)
// OLED Support
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/*
* OLED Screen Connections
* VCC - 5V
@nramsbottom
nramsbottom / IPAddressExtensions.cs
Created May 22, 2018 21:31
IP Slashed Notation Parsing
using System;
using System.Net;
namespace iptest
{
public static class IPAddressExtensions
{
public static uint IPAddressToUint(this IPAddress address)
{
return BitConverter.ToUInt32(address.GetAddressBytes(), 0);
@nramsbottom
nramsbottom / ScanDirectory.cs
Last active March 3, 2020 22:11
Scan directories and run an action for each file and directory therein.
static void ScanDirectory(string directoryPath, Action<string> fileAction, Action<string> directoryAction, string fileSearchPattern = "*", Action<string> unauthorizedAccess = null)
{
if (directoryPath == null) throw new ArgumentNullException(nameof(directoryPath));
if (fileSearchPattern == null) throw new ArgumentNullException(nameof(fileSearchPattern));
if (string.IsNullOrWhiteSpace(directoryPath)) throw new ArgumentException("Path is required.", nameof(directoryPath));
if (string.IsNullOrWhiteSpace(fileSearchPattern)) throw new ArgumentException("Pattern is required.", nameof(fileSearchPattern));
var directories = new Stack<string>();
directories.Push(directoryPath);
@nramsbottom
nramsbottom / msvc-setup.iss
Created September 14, 2017 22:51
Simple InnoSetup for MSVC Application
#define AppDisplayName "Simple Cpp Application"
; this value will be prefixed with the word "version" in the add/remove programs list
#define AppVersion "1.0"
[Setup]
PrivilegesRequired=poweruser
@nramsbottom
nramsbottom / setup.iss
Last active July 18, 2020 00:41
Simple InnoSetup Script for a .NET 4.7 Application
#define AppDisplayName "Simple Application"
; this value will be prefixed with the word "version" in the add/remove programs list
#define AppVersion "1.0"
[Setup]
PrivilegesRequired=poweruser
@nramsbottom
nramsbottom / Program.cs
Created September 8, 2017 05:29
Basic AutoFac Usage
using Autofac; // Install-Package AutoFac
using System;
namespace AutoFacTest
{
class Program
{
static IContainer Container { get; set; }
@nramsbottom
nramsbottom / bubble_sort.c
Created May 28, 2017 12:07
Simple Bubble Sort
#include <stdio.h>
void show(int arr[], int count) {
for (int n = 0; n < count - 1; n++)
printf("%d ", arr[n]);
printf("\n");
}
void bubble_sort(int arr[], int count) {
@nramsbottom
nramsbottom / ApplicationContext.cs
Created May 10, 2017 00:02
EFCoreApp1 - Simple Entity Framework Core App
using Microsoft.EntityFrameworkCore;
namespace EFCoreApp1
{
class ApplicationContext : DbContext
{
public ApplicationContext() { }
public ApplicationContext(DbContextOptions<ApplicationContext> options) : base(options)
{
}