Skip to content

Instantly share code, notes, and snippets.

@rstackhouse
rstackhouse / Program.cs
Last active January 26, 2022 14:54
Console app to generate a gateway to a service using NSwag and a swagger document.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NSwag;
using NSwag.CodeGeneration.CSharp;
namespace GatewayGenerator
{
class Program
@rstackhouse
rstackhouse / Message_Box_Using_Generic_Stack.cs
Created August 8, 2017 02:08
Message Box Using Generic Stack
public class MessageBox
{
private Stack<string> messages = new Stack<string>();
public int MessageCount { get { return messages.Count; } }
public void AddMessage(string message)
{
messages.Push(message);
}
@rstackhouse
rstackhouse / Message_Box_Using_Generic_List.cs
Created August 8, 2017 02:05
Message Box Using Generic List
class MessageBox
{
private List<string> messages = new List<string>();
public int MessageCount { get { return messages.Count; } }
public string this [int i]
{
get { return messages [i]; }
set { messages[i] = value; }
}
$ csharp
@rstackhouse
rstackhouse / play_sound_ev3_usb.js
Last active July 27, 2016 18:24
Make a Lego Mindstorms EV3 brick beep over a USB connection with Node
var LEGO_VENDOR_ID = 0x0694;
var EV3_PRODUCT_ID = 0x0005;
var DIRECT_COMMAND = 0x80;
var usb = require('usb');
var device = usb.findByIds(LEGO_VENDOR_ID, EV3_PRODUCT_ID);
e Json::Value $root1 = Json::Value((Json::ValueType)Json::ValueType::objectValue)
e std::string $str
e $str = "Some string"
e (SomeType*) some_func($str)
@rstackhouse
rstackhouse / connection-string-builder.cs
Created September 17, 2013 16:02
Validate connection strings with connection string builder.
var csb = new DbConnectionStringBuilder();
csb.ConnectionString = "data source=(local);";
Console.WriteLine(csb.ContainsKey("Data Source"));
@rstackhouse
rstackhouse / GetEnumValuesWithSpecificAttributes.cs
Created August 22, 2013 14:49
Getting enum values with specific attributes
void Main()
{
List<Days> weekend = new List<Days>();
Enum.GetValues(typeof(Days)).Cast<Days>().ToList()
.ForEach(d => {
var fi = d.GetType().GetField(d.ToString());
if (fi.GetCustomAttributes(typeof(WeekendAttribute), false).Length > 0)
{
@rstackhouse
rstackhouse / OpenHiddenFileInput.html
Last active December 20, 2015 05:59
Open a hidden file input by clicking a button.
<html>
<head>
<title>Test upload form focused by button press</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<!--Some ideas on better styling methods at http://www.quirksmode.org/dom/inputfile.html-->
<input name="file" id="file" type="file" style="display:none;">