Skip to content

Instantly share code, notes, and snippets.

View jesperbjensen's full-sized avatar

Jesper Blad Jensen jesperbjensen

View GitHub Profile
{
"files": [
"index.ts"
],
"deno_args":[
"--allow-net",
"--allow-read",
"--allow-write"
],
"extensions": [
import { serve } from "https://deno.land/std@0.50.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
let headers = new Headers();
headers.set("content-type", "text/html");
for await (const req of s) {
req.respond({
@jesperbjensen
jesperbjensen / hooks-sample.jsx
Created August 12, 2019 07:43
Hooks Form Prototype Example
function MyFormSample() {
const form = useForm({
firstName: useField({ name: "Firstname", validators: [requiredValidator] }),
lastName: useField({ name: "Lastname", validators: [requiredValidator] })
});
return (
<div>
<TextField {...textFieldFieldProps(form.firstName)} />
<TextField {...textFieldFieldProps(form.lastName)} />
@jesperbjensen
jesperbjensen / react-flux-dispatcher.ts
Created October 8, 2015 16:07
A TypeScript conversion of the React Flux Dispatcher
class Dispatcher {
_callbacks: { [key: string]: (payload: IActionPayload) => void };
_isDispatching: boolean;
_isHandled: { [key: string]: boolean };
_isPending: { [key: string]: boolean };
_lastID: number;
_pendingPayload: IActionPayload;
constructor() {
this._callbacks = {};
@jesperbjensen
jesperbjensen / Startup.cs
Last active August 29, 2015 14:16
A snippet that shows two ways to read files using ASP.NET 5
// Using File.ReadAllText
public async Task MyMiddleWare(HttpContext context, IApplicationEnvironment env)
{
var html = File.ReadAllText(env.ApplicationBasePath + "/Views/index.html");
await context.Response.WriteAsync(html);
}
// Using FileProvider
@jesperbjensen
jesperbjensen / Startup.cs
Created March 7, 2015 14:06
A simple snippet for writing hello world using ASP.NET 5
// Inline lampda:
public void Configure(IApplicationBuilder app)
{
// "" is the route - so this is just the root path
app.Map("", x =>
{
x.Run(m => m.Response.WriteAsync("Hello, World!"));
});
}
@jesperbjensen
jesperbjensen / syntax.cshtml
Created June 14, 2013 14:29
Alternative HtmlHelper Syntax
@using (Html.BeginRouteForm(Route.Stuff, FormMethod.Get, new {@class = "myForm", data_hello = "this"}))
{
...
}
@using (Html.Form.Method(FormMethod.Get).Src(Route.Stuff).Class("myForm").Data_Hello("this"))
{
}
@jesperbjensen
jesperbjensen / search.html
Created April 2, 2013 13:39
A simple little form, that searches on google, filtered to your site.
<form method="get" action="https://google.com/search">
<input type="hidden" name="as_sitesearch" value="deldy.dk">
<input type="search" name="q" placeholder="search">
<input type="submit" style="display:none;">
</form>
@jesperbjensen
jesperbjensen / UrlStortenerHelper.cs
Last active December 15, 2015 09:49
A little helper class that helps shorten URL's from Bit.ly
using BitlyDotNET.Implementations;
using BitlyDotNET.Interfaces;
//NUGET:
// Install-Package Bitly.Net
//Get username and apiKey from BIT.LY - you can get it under your account, settings > advanced and then Legacy API Key.
public class UrlShortenerHelper
{
public static void Setup(string username, string apiKey)