Skip to content

Instantly share code, notes, and snippets.

View earlin's full-sized avatar
👨‍💼
Looking for a job

earlin

👨‍💼
Looking for a job
View GitHub Profile
export default function hash(string) {
const length = string.length;
let h = 0, a = 63689, b = 378551;
for (let i = 0; i < length; i++)
{
h = (Math.imul(h, a) + string.charCodeAt(i)) >>> 0;
a = Math.imul(a, b) >>> 0;
}
return h;
}
https://flems.io/#0=N4Igxg9gdgzhA2BTEAucD4EMAONEBMQAaEAMwEskZUBtUKTAW2TQDoALAF0fmPSk6IBqECAC+RekxYhWAK2olIAoZxHKYnAAQBleOXyIATloC8W4AB0o1rXa3RyUcpwAUUCIYCUF2-f8ehqyamIKsAG6Y8ACuiGZagYisoZxGMBFRsQDcfv52icGcoUlGmFAA5nHmALKh7MkARjDunkkpaayMmAAeWgC0Ca3JnKnpjE5eOVD+Eta5WuHkiADuLd6+NtN5dhrawFrjUEQHPVpi8QXtMFPbO9CaWiGCF0NPiDe3uxZapRVx5+Y3lN5v4vpEYlUtK5XGAsIxsK43hkIcdDqiej4APQ-MqVHwAKi0AEYAAwkrysTgQABi5G6BFcACZJiD7F9GBBongABJlfBIEzmVyIHymAB8G1ueSSmgg2AACkY5ZhyqFyNBXCytlK7EjwbF4vrENSlYwAPKkUh4TgADWFrAglutNtRTmOvzxH22YmB2ryRkQnGiRmmjFcAHJhlA+jB9IYjOHjlY-VLoLDyGAANYoA6cnl8gVEVnbaAcrmIDnhRA5sv5qD84zFs7HGhN-xhyOhaOpTBZ8NeIsp24dqN9I2J76aACeSBzAANlgZOOwcwASYBGsQAUjnZwHbfsI67fWX0UYDQnyZ1t2ns60c6QpE4a43mUQ27ng+vdjEXibAF0tRmOYoDEEDSGiKAwE4dVpiNE0IHNJ1AztbpXSOHE-h8K97ADIMQwOJwtAAaihXpsUZMkCUwyopjAzYIKgmDoC0WEmARI10PRbpsPmPDg2mWpl06HpXDRLQhPqQ4xJ6Y4jS8P9QJAr4AEFsGweIcLsRYVk1SVbn4giwz0AxjCTA87EOHMSW4nNSRshY3xzAB2Ekm1-L0zmsH0QMYTpOQEVx8AgMAz1UVgGk8KdjjU7BJj4SB4UoYxUCgaJ4HgEg8CQaDYOoNBnJQIkADZxEkEAGGYERWDAGBFH4QRhDQSL8CnfS7AaXtM3KJ
@earlin
earlin / canvas.ts
Created March 23, 2019 11:46
I'm just playing with mithril until I made a pen tool :D
export const Canvas: Mithril.FactoryComponent = () => {
let canvas: HTMLCanvasElement, context: CanvasRenderingContext2D;
let points: number[] = [];
let data: ImageData;
function onMouseDown(e: MouseEvent) {
data = context.getImageData(0, 0, canvas.width, canvas.height);
points.push(e.offsetX, e.offsetY);