Skip to content

Instantly share code, notes, and snippets.

View rsms's full-sized avatar

Rasmus rsms

View GitHub Profile
@rsms
rsms / EventListener.d.ts
Created July 12, 2017 17:49
Better EventEmitter TypeScript interface
export class EventEmitter<Events, K = keyof Events|symbol> {
addListener(event: K, listener: (...args: any[]) => void): this;
on(event: K, listener: (...args: any[]) => void): this;
once(event: K, listener: (...args: any[]) => void): this;
removeListener(event: K, listener: (...args: any[]) => void): this;
removeAllListeners(event?: K): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(event: K): Function[];
emit(event: K, ...args: any[]): boolean;
@rsms
rsms / spotlight-ax.m
Created May 10, 2009 16:45 — forked from liesen/gist:109666
A small utility that observes any changes of a search field of a given application
/* Cocoa accessibility framework for intercepting Spotlight user input. */
#import <Cocoa/Cocoa.h>
#import <AppKit/NSAccessibility.h>
static CFStringRef kSpotlightBundleIdentifier = CFSTR("com.apple.spotlight");
static void SpotlightCallback(AXObserverRef observer,
AXUIElementRef element,
struct WorldGrid {
static const size_t vertexDataStride = 6;
wgpu::Buffer _indexBuffer;
wgpu::BindGroup _bindGroup;
wgpu::DepthStencilState _depthStencil;
wgpu::RenderPipeline _pipeline;
WorldGrid() {
_depthStencil.format = wgpu::TextureFormat::Depth24PlusStencil8;
#!/bin/sh
#
# Usage:
# sh build-fontkit.js.sh [<outfile>]
# <outfile> defaults to ./fontkit-VERSION.js
#
# This script builds fontkit.js for a web browser as an ES module script.
# Use the result like this:
# <script type="module">
# import fontkit from "./fontkit-2.0.2.js"
figma.showUI(`<script>
let imurl = 'https://66.media.tumblr.com/7af65560449c91e8cd82a4a3478f5e0b/tumblr_pb7bt5CTrS1qzdllao1_1280.jpg'
fetch(imurl).then(r => r.arrayBuffer()).then(a =>
parent.postMessage({ pluginMessage: ["imdata", new Uint8Array(a)] }, '*'))
</script>`, { visible:false, width:200, height:200 })
figma.ui.onmessage = msg => {
if (msg[0] == "imdata") {
let data = msg[1] as Uint8Array
let imageHash = figma.createImage(new Uint8Array(data)).hash
const rect = figma.createRectangle()
@rsms
rsms / 00-readme.md
Created May 12, 2020 22:50
TensorFlow-GPU on a dedicated remote PC, using a Mac for development

My random notes on the adventure of developing with TensorFlow on a Mac, running calculations on a NVIDIA GPU in a separate PC. Your miles may vary.

{
pkgs ? (import <nixpkgs> {}).pkgsMusl
}:
let
inherit (pkgs) lib;
llvmPkgs = pkgs.llvmPackages_13;
stdenv = llvmPkgs.stdenv;
# stdenv = llvmPkgs.libcxxStdenv;
mkShell = pkgs.mkShell.override { inherit stdenv; };
hello_c = pkgs.writeText "hello.c" ''
@rsms
rsms / gist:3564654
Created September 1, 2012 05:33
Life is purposeless. And it is beautiful that it is purposeless

Life is purposeless. And it is beautiful that it is purposeless

It is very difficult, particularly for the Western mind, to understand that life is purposeless. And it is beautiful that it is purposeless. If it is purposeful then the whole thing becomes absurd – then who will decide the purpose? Then some God has to be conceived who decides the purpose, and then human beings become just puppets; then no freedom is possible. And if there is some purpose then life becomes businesslike, it cannot be ecstatic.

The West has been thinking in terms of purpose, but the East has been thinking in terms of purposelessness. The East says life is not a business, it is a play. And a play has no purpose really, it is nonpurposeful. Or you can say play is its own purpose, to play is enough. Life is not reaching towards some goal, life itself is the goal. It is not evolving towards some ultimate; this very moment, here and now, life is ultimate.

Life as it is, is accepted in the East. It is not moving towards some end, b

@rsms
rsms / example-project.js
Created February 6, 2017 03:20
tspkg example project output from `tspkg -O` (1422 kB)
"use strict";(typeof define=="undefined"?function(a,b){return function(c,e,h){b=b||function(j){return a[j]},h.apply(a,[b,typeof exports=="undefined"?a[c]={}:exports].concat(e.slice(2).map(b)))}}(this,typeof require=="undefined"?0:require):define)("example-project",["require","exports","vm","util"],function(a,b,c,e){function h(u){if(9999!=u)throw new Error("bob"+c.createContext());return 1.2/u}function j(u){return 6*u}function k(u){return console.log("d:",e.inspect(u)),c.createContext(),j(2*u)}function l(u){return u+"-"+(j+"")}function n(u){return 9.1*u}Object.defineProperty(b,"__esModule",{value:true});const o={__esModule:true};const p={__proto__:o,Animal:class{constructor(w){this.furry=w}isFurry(){return this.furry}},a2:h,default:function(w){return 1/w}};const q=a("fs");a("crypto");console.log("c:",k(456+p.default(789)),4936);const r=1234;const s={__proto__:o,foo:function(w){return l(w)+" from foo/index"},default:{c:r}};console.log("hello from e"+(a("crypto")&&r));const t={sections(u){return"x"+u}};b.a=p,b["