This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
namespace ZC | |
{ | |
class Program | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn read() -> String { | |
let mut buffer = String::new(); | |
std::io::stdin().read_line(&mut buffer).ok(); | |
if buffer.ends_with("\n") { | |
buffer.pop(); | |
} | |
if buffer.ends_with("\r") { | |
buffer.pop(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Security.Cryptography; | |
namespace JA | |
{ | |
// Credit for CryptoRandom goes to Stephen Toub & Shawn Farkas, original | |
// authors of the code included below, which appeared in September 2007 | |
// in MSDN Magazine. | |
// | |
// http://blogs.msdn.com/b/msdnmagazine/archive/2007/08/31/4653696.aspx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using CsvHelper; | |
using CsvHelper.Configuration; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
namespace AirlineDelays | |
{ | |
class FlightRecord |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(slice_patterns)] | |
extern crate csv; | |
extern crate itertools; | |
extern crate rustc_serialize; | |
use std::cmp::Ordering; | |
use std::collections::HashMap; | |
use std::path::Path; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{self}; | |
use std::result; | |
type KKResults <T> = Result <T, KKError>; | |
#[derive(Debug)] | |
enum KKError { | |
Io(io::Error), | |
} |