Skip to content

Instantly share code, notes, and snippets.

/*
* Bookmarklet for viewing source in iPad Safari
*/
javascript:(function(){
var w = window.open('about:blank'),
s = w.document;
s.write('<!DOCTYPE html><html><head><title>Source of ' + location.href + '</title><meta name="viewport" content="width=720, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0" /></head><body></body></html>');
s.close();
@rhwy
rhwy / Nancy fix update
Created June 20, 2012 08:21
Temporary fix for nunit tests with Nancy FX and Monodevelop runner
// 2)
public static class AppDomainAssemblyTypeScannerIgnoreHelper
{
private static IEnumerable<Func<Assembly,bool>> _ignoreList;
public static IEnumerable<Func<Assembly,bool>> IgnoreList
{
get { return _ignoreList;}
set {_ignoreList = value;}
}
@rhwy
rhwy / 01_Sample_Result.cs
Created July 4, 2012 23:02
Discussion : Attempt to add units to numbers in C# in a simple and clean way
void Main()
{
var a = (Meter)123 + (Kilometer)2.3 + (Centimeter)1234;
Console.WriteLine(a.ToString());
Console.WriteLine(a.To<Kilometer>().ToString());
Console.WriteLine(a.To<Centimeter>().ToString());
var b = (Meter)2 * (Centimeter)30;
Console.WriteLine(b.ToString());
Console.WriteLine(b.ToSurface<Centimeter>().ToString());
@rhwy
rhwy / 01_cart.cs
Last active December 26, 2015 19:19
Following my tweet discussion https://twitter.com/rhwy/status/394729592118071296, let's put some code to clarify inputs. The code is in C# but near to pseudo-code and other languages to be clear for all (I hope :-) I tend to be the more specific as possible but sometimes I smell that it should be over-engineered too. As usual it depends on the c…
//Imagine you have a Cart with items you can add into
public class Cart
{
public int Id {get;private set}
public List<CartItem> Items {get;private set}
public Cart(int id) { Id = id;}
//while writing your tests, you (want to) arrive to these checks (3 situations to test)
public void AddItem(CartItem item) {
@rhwy
rhwy / getcountryforip.cs
Created May 29, 2014 10:57
a small working sample of a tool as simple as possible using webclient (and async)
namespace nurl1
{
class Program
{
public static void Main(string[] args)
{
if(args.Length<1 || !(Regex.Match(args[0],@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b").Success))
throw new ArgumentException("not a valid ip number");
Console.WriteLine("Country for ip [{0}]",args[0]);
@rhwy
rhwy / gist:72eb2936ad045b300f48
Created November 26, 2014 17:16
NancyFX returning struct as Json
public class HomeModule : NancyModule
{
public HomeModule ()
{
Get ["/"] = p => "hello";
Get ["/{id}/{user}"] = p => {
User user = new User(p.id,p.user);
return Negotiate.WithModel(user);
};

Keybase proof

I hereby claim:

  • I am rhwy on github.
  • I am rhwy (https://keybase.io/rhwy) on keybase.
  • I have a public key whose fingerprint is B16B AF86 1DC2 478C F7FC 0BBF 7111 E669 FBFD 11A9

To claim this, I am signing this object:

#hello

@rhwy
rhwy / win2018inst.bat
Created April 7, 2018 14:31
Install workstation with chocolatey
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" > "c:\install-log.txt"
cinst googlechrome -y
@rhwy
rhwy / choco-installs.ps1
Last active April 7, 2018 16:07
Install workstation with chocolatey
cinst python -y
cinst nodejs -y
cinst jre8 -y
cinst git.install -y
cinst dotnetcore-sdk -y
cinst dotnet4.7.1 -y
cinst azure-cli -y
cinst microsoftazurestorageexplorer -y
cinst ngrok -y