Skip to content

Instantly share code, notes, and snippets.

@coltonhurst
coltonhurst / .gitignore
Created March 5, 2024 05:27 — forked from kmorcinek/.gitignore
.gitignore for C# projects
# The following command works for downloading when using Git for Windows:
# curl -LOf http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore
#
# Download this file using PowerShell v3 under Windows with the following comand:
# Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore
#
# or wget:
# wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore
# User-specific files
@coltonhurst
coltonhurst / main.rs
Last active October 20, 2020 16:27
Console args and input idiomatically in Rust
/*
Thanks @seri & others (from the Rust Discord) for the help!
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2e1705d582a07f1d59897a21ae2421d6
- no more realloc of all of the args into a vec if you just want the second one
- or_else to call get_zipcode_from_user if the arg is not present, ok() to convert a result into an option
- return a result
- ? for fast return in case of an error
https://doc.rust-lang.org/std/option/enum.Option.html#method.or_else
@coltonhurst
coltonhurst / server.go
Created March 11, 2020 13:42
Simple Go Web Server
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
@coltonhurst
coltonhurst / Program.cs
Created January 15, 2020 15:12
Interface Example
using System;
namespace learning
{
class Program
{
static void Main(string[] args)
{
// Make myCar
Car myCar = new Car();
@coltonhurst
coltonhurst / main.go
Created November 13, 2019 20:24
Handling HTTP verbs by hand with Go
// https://dev.to/moficodes/build-your-first-rest-api-with-go-2gcj
package main
import (
"log"
"net/http"
)
type server struct{}
@coltonhurst
coltonhurst / main.rs
Last active September 12, 2019 19:48
When giving bad input, it breaks!
/*
The Cashier Program
A simple program that accepts two user inputs:
1) The total the customer owes
2) The amount in cash the customer paid with
This program returns the most effiecient option for giving change back to the customer.
*/
@coltonhurst
coltonhurst / hello-world.js
Created July 30, 2019 17:35
A barebones node.js web server.
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer(function (req, res) {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});
@coltonhurst
coltonhurst / Runner.cs
Last active July 30, 2019 17:36
Serializing objects to XML with C#
using System;
using System.Xml.Serialization;
using System.IO;
namespace SerializeTester
{
public class Runner
{
static void Main(string[] args)
{
@coltonhurst
coltonhurst / game.c
Created February 22, 2019 02:39
Example SDL Window
#include <SDL.h>
#include <stdio.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main(int argc, char* args[])
{
SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;
@coltonhurst
coltonhurst / remove-all-but-letters-and-newlines.cs
Last active October 1, 2018 21:05
Remove all characters except for letters and newlines
// A very inefficient way to remove everything from a file except for letters and newlines.
class Program
{
static void Main(string[] args)
{
string text = System.IO.File.ReadAllText(@"original-file.txt");
string newText = "";
for (int i = 0; i < text.Length; i++) {
if (Char.IsLetter(text, i) || text[i] == '\n') {