Skip to content

Instantly share code, notes, and snippets.

@ijt
ijt / lit-element.html
Created May 22, 2020 18:10
Minimal HTML page using LitElement
<!doctype html>
<html>
<head></head>
<body>
<my-element></my-element>
<script type="module">
import {LitElement, html} from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module';
class MyElement extends LitElement {
render() {
<script type="module">
import {html, render} from 'https://unpkg.com/lit-html?module';
const myTemplate = (name) => html`<p>Hello ${name}</p>`;
render(myTemplate('World'), document.body);
</script>
@ijt
ijt / hijax.html
Created March 16, 2020 19:02
Intercept Ajax calls and make them do something else
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<div id="d">nothing here yet</div>
<script>
var send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(body) {
@ijt
ijt / stringsim.rs
Created October 3, 2019 00:36
Rust program to compute the trigram Jaccard similarity between two strings
//! The stringsim program prints out the trigram similarity of two strings
//! using what appears to be the same algorithm used by Postgres.
//! https://www.postgresql.org/docs/9.1/pgtrgm.html
use std::collections::HashSet;
use std::hash::Hash;
fn main() {
let args: Vec<String> = ::std::env::args().collect();
if args.len() != 1+2 {
@ijt
ijt / gofast_issue_28.go
Created July 20, 2018 16:32
Repro case for gofast issue 28
// This program spins up php-fpm in the background and a Go web server sending
// all requests to a PHP router script.
package main
import (
"context"
"flag"
"fmt"
"io/ioutil"
"log"
@ijt
ijt / mfilt
Created November 26, 2017 01:23
#!/usr/bin/env python
import argparse
import re
import sys
parser = argparse.ArgumentParser(description=
'''Filter some text with a regex, allowing matches to span multiple lines.
This tool is based on some ideas from Rob Pike's Sam editor:
@ijt
ijt / sieve.clj
Last active February 21, 2016 06:09
Translation of the Go prime sieve to Clojure
;; A concurrent prime sieve translated from
;; https://golang.org/doc/play/sieve.go
;; by Issac Trotts with help from Chris Murphy and glts on Stack Overflow.
(require '[clojure.core.async :as async :refer [<! >! <!! chan go]])
(defn generate-naturals
"Sends the sequence 2, 3, 4, ... to channel 'ch'."
[ch]
(go
@ijt
ijt / sieve.erl
Last active February 20, 2016 05:03
Translation of the Go prime sieve to Erlang
#!/usr/bin/env escript
%% -*- mode: erlang -*-
%%! -smp enable -hidden
%%
%% A concurrent prime sieve, inspired by the Go prime sieve
%% with daisy-chained filter processes.
%% https://golang.org/doc/play/sieve.go
%%
%% Translated by Issac Trotts (2016)
%% with help from Amiramix on StackOverflow.
@ijt
ijt / quine.go
Created November 7, 2012 05:07
A quine in Go
package main
import "fmt"
func main() {
s := "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ts := %#v\n\tfmt.Printf(s, s)\n}\n"
fmt.Printf(s, s)
}
@ijt
ijt / splat.go
Created October 26, 2012 20:22
Argument splatting in Go
// See https://code.google.com/p/go/issues/detail?id=640
package main
import "fmt"
func main() {
args := []int{1, 2, 3}
fmt.Println(sum(args...))
}