Skip to content

Instantly share code, notes, and snippets.

View mythz's full-sized avatar

Demis Bellot mythz

View GitHub Profile
@mythz
mythz / 01-WebApiProducts.cs
Created October 13, 2012 23:40
Your First ASP.NET Web API Products Example vs ServiceStack
/* Tutorial example from:
* Your First ASP.NET Web API (C#):
* http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
*/
namespace HelloWebAPI.Controllers
{
public class ProductsController : ApiController
{
Product[] products = new Product[]
{
@mythz
mythz / RpcVsMessages.md
Created November 22, 2011 18:02
Difference between an RPC-chatty and message-based API

Difference between an RPC-chatty and message-based API

	public interface IService
	{
	  Customer GetCustomerById(int id);
	  Customer[] GetCustomerByIds(int[] id);
	  Customer GetCustomerByUserName(string userName);
	  Customer[] GetCustomerByUserNames(string[] userNames);
 Customer GetCustomerByEmail(string email);
@mythz
mythz / HelloImage.cs
Created April 6, 2012 18:04
Different ways of returning an ImageStream
// 3 different ways to return an image.
// More info about other responses http://stackoverflow.com/questions/6245616/does-servicestack-support-binary-responses
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using ServiceStack.Common.Web;
using ServiceStack.Service;
@mythz
mythz / xhr.js
Created November 2, 2011 19:05
Standalone jQuery-like Ajax Client
//Adds $.xhr and jQuery-like $.ajax methods to the prescribed namespace.
//Inspired from David Flanagans excellent cross-platform utils http://www.davidflanagan.com/javascript5/display.php?n=20-1&f=20/01.js
//Includes underscore.js _.each and _.extend methods
//modified to behave like jQuery's $.ajax(), not complete.
(function($) {
var win=window, xhrs = [
function () { return new XMLHttpRequest(); },
function () { return new ActiveXObject("Microsoft.XMLHTTP"); },
function () { return new ActiveXObject("MSXML2.XMLHTTP.3.0"); },
function () { return new ActiveXObject("MSXML2.XMLHTTP"); }
@mythz
mythz / vanilla.js
Last active March 4, 2021 14:56
3 missing JS functions
let $ = (sel, el) => typeof sel === "string" ? (el || document).querySelector(sel) : sel || null,
$$ = (sel, el) => Array.prototype.slice.call((el || document).querySelectorAll(sel));
function on(sel, handlers) {
$$(sel).forEach(e => {
Object.keys(handlers).forEach(function (evt) {
let fn = handlers[evt];
if (typeof evt === 'string' && typeof fn === 'function') {
e.addEventListener(evt, fn.bind(e));
}
@mythz
mythz / keybase.md
Created February 16, 2021 08:40
keybase.md

Keybase proof

I hereby claim:

  • I am mythz on github.
  • I am mythz (https://keybase.io/mythz) on keybase.
  • I have a public key ASAeJidstT7bc7YfiJpDh_XTzcEFOsssBSa-CfwM_aQJlwo

To claim this, I am signing this object:

@mythz
mythz / basic-fsharp-gtk-demo.fs
Created September 15, 2011 05:16
Basic F# demo using Mono Gtk#
let btnUp = new Button("Increment", Visible=true)
let btnDown = new Button("Decrement", Visible=true)
let lbl = new Label(Text=" Count: 0", Visible=true)
Event.merge
(btnUp.Clicked |> Event.map (fun _ -> +1))
(btnDown.Clicked |> Event.map (fun _ -> -1))
|> Event.scan (+) 0
|> Event.map (sprintf " Count: %d")
|> Event.add (fun s -> lbl.Text <- s)
@mythz
mythz / IServiceClient.cs
Created July 6, 2015 01:43
Combined IServiceClient Interfaces
namespace ServiceStack
{
public interface IServiceClient : IServiceClientAsync, IOneWayClient, IRestClient, IReplyClient, IHasSessionId, IHasVersion
{
int Version { get; set; } //IHasVersion
string SessionId { get; set; } //IHasSessionId
//IReplyClient:
TResponse Send<TResponse>(object request);
TResponse Send<TResponse>(IReturn<TResponse> request);
@mythz
mythz / main.cs
Last active December 2, 2020 06:45
Custom SQL Issue
using System;
using System.Linq;
using ServiceStack;
using ServiceStack.Text;
using ServiceStack.OrmLite;
using ServiceStack.OrmLite.Sqlite;
using ServiceStack.DataAnnotations;
var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
var db = dbFactory.Open(); // Open ADO.NET DB Connection