Skip to content

Instantly share code, notes, and snippets.

@archer884
archer884 / partial.rs
Last active September 10, 2015 15:45
Rust weirdness
// This does not work without the move marker. The reason for that is that the lifetime for `a`
// only covers the scope of the outer function, which does not extend to the scope of the inner
// function, which is returned from the outer function.
fn main() {
let x = |a| move |b| a + b;
let y = x(5);
let z = y(5);
println!("{}", z); // prints 10
}
/Closes the window and commits the order to the database
private void btnComplete_Click(object sender, EventArgs e)
{
using(var conn = new OleDbConnection(Utilities.CONNECTION_STRING))
{
OleDbCommand cmd = new OleDbCommand
("INSERT INTO tblOrders ([OrdersProducts],[OrdersSoldTo],[OrdersTotalPrice])Values(@Products,@Clients,@TotalCost)");
cmd.Connection = conn;
conn.Open();
if (conn.State == ConnectionState.Open)
@archer884
archer884 / ZC.cs
Created May 7, 2015 22:29
Checks zippopotam.us to see if a zip code is valid
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
namespace ZC
{
class Program
{
@archer884
archer884 / convert.rs
Last active August 29, 2015 14:19
Distances and conversions (with macro)
use std::fmt;
use std::ops;
trait Distance {
type Value;
fn to_normal(&self) -> f64;
fn from_normal(f64) -> Self::Value;
}
/// Creates a distance type.
@archer884
archer884 / convert.rs
Last active August 29, 2015 14:19
Distances and conversions
use std::fmt;
use std::ops::Add;
trait Distance {
type Value;
fn to_normal(&self) -> f64;
fn from_normal(f64) -> Self::Value;
}
/// This is an attempt at providing a default implementation of the add trait on the Distance trait
@archer884
archer884 / struct_variants.rs
Created April 20, 2015 22:39
Struct enum variants
enum TestEnum {
DataA { f: String, l: String },
DataB { n: String },
}
impl std::fmt::Display for TestEnum {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match self {
&TestEnum::DataA { ref f, ref l } => write!(fmt, "{}, {}", l, f),
&TestEnum::DataB { ref n } => fmt.write_str(&n),
@archer884
archer884 / tip.rs
Last active August 29, 2015 14:16
Tip calculator
struct TipResult {
amt: f64,
tip: f64,
}
fn main() {
let args: Vec<_> = std::env::args().collect();
let tip = match &args[..] {
[_, ref amt] => get_tip(amt.parse().ok(), Some(0.15f64)),
@archer884
archer884 / computus.cs
Created February 18, 2015 23:53
Super-Computus Easter calculator!
using System;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
namespace Computus
{
class Program
{
static Regex NodePattern = new Regex(@"<pre>.*?</pre>", RegexOptions.IgnoreCase|RegexOptions.Singleline);
using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var propertyValue = GetValidDecimalInput();
var propertyTax = PropertyAssessment(propertyValue) * 0.0064m;
@archer884
archer884 / ext.rs
Last active October 24, 2021 23:08
"Extension Methods" in Rust
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use std::collections::hash_state::HashState;
fn main() {
if let Some(content) = {
let args = std::os::args();
if args.len() == 2 {
Some(args[1].to_string())
} else {