Skip to content

Instantly share code, notes, and snippets.

@tdshipley
tdshipley / teardown_setup_bad_example.cs
Last active February 5, 2016 13:20
An example of why using a Setup and Teardown method in tests can be bad from: http://jamesnewkirk.typepad.com/posts/2007/09/why-you-should-.html
[TestFixture]
public class MyTests
{
[SetUp]
public void BeforeTest()
{
Console.WriteLine("BeforeTest");
}
[TearDown]
@tdshipley
tdshipley / get_using_httpclient.cs
Last active March 10, 2023 16:17
An example of GET request using HttpClient in C#
namespace API.Controllers
{
public class GithubController : ApiController
{
private const string _address = "https://api.github.com/users/tdshipley";
private const string _userAgent = "TestApp";
// GET api/<controller>
public async Task<string> Get()
{
@tdshipley
tdshipley / static_method.cs
Created December 9, 2015 22:44
Example of a static method in C#
private static bool IsJpegMatch(byte[] block)
{
// Implementation of IsJpegMatch method omitted
}
# Taken from http://stackoverflow.com/questions/3668345/calculate-percentage-in-ruby
class Numeric
def percent_of(n)
self.to_f / n.to_f * 100.0
end
end
1.percent_of 10 # => 10.0 (%)
@tdshipley
tdshipley / ruby_precentage_sudo_code.rb
Created September 1, 2015 19:54
Sudo code for a ruby percentage method that would be nice to have
10.percentage_of 100 # => 10
@tdshipley
tdshipley / marshal_unmarshal_ymal_go.go
Last active August 31, 2015 22:23
An example of marshling and unmarshling YAML in GO
package main
import (
"gopkg.in/yaml.v2"
)
var data = `
- name: 'Thomas'
- age: 25
`
@tdshipley
tdshipley / go_yaml_struct.go
Created August 31, 2015 22:09
A YAML struct for Go
type Person struct {
Name string `yaml:"name"`
Age int `yaml:"age"`
}
@tdshipley
tdshipley / go_yaml_import.go
Created August 31, 2015 22:05
Import statement for go-ymal
package main
import (
"gopkg.in/yaml.v2"
)
@tdshipley
tdshipley / go_json_struct.go
Created August 31, 2015 21:51
Go Struct for JSON
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
}
@tdshipley
tdshipley / question_mark_ruby_example.rb
Created July 13, 2015 21:01
Ruby Question Mark Method Example
until file.eof?