Skip to content

Instantly share code, notes, and snippets.

View infinnie's full-sized avatar
🙃
Actively ignorant.

joan xie infinnie

🙃
Actively ignorant.
View GitHub Profile
precision highp float;
uniform vec3 origResolution;
uniform vec3 iResolution;
uniform sampler2D iChannel0;
uniform bool flip;
uniform vec2 direction;
vec4 blur9_1_0(sampler2D image, vec2 uv, vec2 resolution, vec2 direction, vec2 a) {
vec4 color = vec4(0.0);
vec2 off1 = (vec2(1.3846153846) * direction) / resolution;
vec2 off2 = (vec2(3.2307692308) * direction) / resolution;
@infinnie
infinnie / Program.cs
Created March 29, 2019 01:14
Fixed Point Combinator in C#
using System;
namespace ConsoleApp1
{
class Program
{
delegate T Out<T>(T x);
delegate Out<T> RecOut<T>(RecOut<T> x);
class YClass<T>
{
@infinnie
infinnie / ElementContext.jsx
Last active January 4, 2021 09:54
Inject styles like child components
var ElementContext = React.createContext(null);
class ElementContextComponent extends React.Component {
constructor(props) {
super(props);
this.elementRef = React.createRef();
}
render() {
return (
<ElementContext.Provider value={{elRef: this.elementRef, styles: {}, timeout: null}}>
@infinnie
infinnie / chart.js
Last active October 29, 2018 08:23
Tree to D3 chart
function treeGraph(t){
var resultPoints=[],resultLines=[];
resultPoints.push({name:t.name});
if(t.children){
t.children.forEach(function(ct){
var childResult=treeGraph(ct);
resultLines.push({
source: t.name,
target: ct.name
});
@infinnie
infinnie / BridgingComponent.jsx
Created September 10, 2018 10:42
Hook the document fragment.
var SomeReactComponent = class extends React.Component {
render() {
return this.props.render();
}
};
export default {
props: {
reactComponent: Function,
reactComponentProps: {
@infinnie
infinnie / component.jsx
Created May 30, 2018 07:48
Hyperapp eventOptions proposal
import { EventOptions } from "hyperapp-event-options"; // assuming there existed something like that
export function Component(props) {
return (<button on={{
click: [
props.doSomething,
EventOptions.preventDefault | EventOptions.stopPropagation | EventOptions.hookDocument | EventOptions.capture
]
}}>Button content</button>);
}
@infinnie
infinnie / flatArraysAndFunctions.js
Last active May 24, 2018 02:43
Make arrays and functions flat.
var some = function (x) {
if (Array.isArray(x)) {
return [].concat.apply([], x.map(some));
}
if (typeof x === "function") {
return some(x());
}
return x;
};
@infinnie
infinnie / church-encoding.ts
Created May 17, 2018 09:08
Church Encoding in TypeScript
type Some<T> = (x: T) => T;
var add = function <T>(m: Some<Some<T>>, n: Some<Some<T>>) {
return function (f: Some<T>) {
return function (x: T) {
return m(f)(n(f)(x));
};
};
}, mul = function <T>(m: Some<Some<T>>, n: Some<Some<T>>) {
return function (f: Some<T>) {
return m(n(f));
@infinnie
infinnie / random.js
Last active May 15, 2018 02:02
JavaScript generate something random
[...crypto.getRandomValues(new Uint8Array(8))].map(function (x) {
var t = x.toString(16);
return t.length === 2 ? t : "0" + t;
}).join("");
@infinnie
infinnie / dns.js
Created May 8, 2018 03:01
DNS lookup
module.exports.handler = function(event, context, callback) {
require("dns").lookup("gist.github.com",function(...x){
callback(...x);
});
};