Skip to content

Instantly share code, notes, and snippets.

View talyian's full-sized avatar

Jimmy Tang talyian

View GitHub Profile
@talyian
talyian / getresolution.fsx
Created September 30, 2017 00:30
WinGDI Get All supported Monitor Resolutions
#nowarn "9"
open System
open System.Runtime.InteropServices
[<StructLayout(LayoutKind.Sequential)>]
type DEVMODEInfo = struct
[<MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)>]
[<DefaultValue>] val mutable dmDeviceName : string
[<DefaultValue>] val mutable dmSpecVersion: int16;
[<DefaultValue>] val mutable dmDriverVersion: int16;
#r "System.Drawing"
#r "OpenTK"
open OpenTK
open OpenTK.Graphics
open OpenTK.Graphics.OpenGL4
let window = new GameWindow (400,400,
GraphicsMode.Default, "",
GameWindowFlags.Default,
DisplayDevice.Default,
@talyian
talyian / arithmetic
Last active June 30, 2017 23:50
Not a good interview problem
EVAL=(lambda F,B,V,P,T:lambda e:F(T(e),F,P,B(B,V))[0])(
lambda t,f,p,b: [p(p,t,(lambda x:b(('+','-'),b(('*','/'),x))))],
lambda b,e: lambda ops,t,i=0: t if i >= len(t) else b(b,e)(ops,(t.__setslice__(i-1,i+2,[e(t[i],t[i-1],t[i+1])]) or t),i) if t[i] in ops else b(b,e)(ops,t,i+1),
lambda o,x,y: {'+':lambda a,b:a+b, '-':lambda a,b:a-b, '*':lambda a,b:a*b, '/':lambda a,b:a/b}[o](float(x), float(y)),
lambda p, t, f: f((lambda s,e:t.__setslice__(s,e+1,[p(p,t[s+1:e], f)]) or t)(t.index('('),len(t)-1-t[::-1].index(')')) if '(' in t else t)[0],
lambda e: [x for x in __import__('re').split('(\\d+|.)', e.replace(' ', '')) if x],
)
print EVAL("3 - 5 - 4 - 3");
print EVAL("3 * 5 + 4 / 3");
print EVAL("3 * (5 + 4) / 2");
@talyian
talyian / door_opener.ino
Created June 30, 2017 23:25
Door Opener
#include <ESP8266WiFi.h>
const int BUZZER_INPUT_IO = 5;
const int DOOR_OUTPUT_IO = 4;
const int LED_IO = 0;
enum { STARTING, READY, NOTIFYING, OPENING };
void setup() {
Serial.begin(115200);
@talyian
talyian / mandelbrot.html
Created June 13, 2017 20:22
Mandelbrot set in WebGL
<style>body { background: black; } #cv { display:block; margin:auto; }</style>
<canvas id='cv' width='800' height='800'></canvas>
<script id=frag type='x-shader/fragment'>
precision highp float;
varying vec2 _pos;
void main() {
vec2 c = _pos * 1.5 - vec2(0.7, 0), z;
for(int i = 0; i < 64; i++) {
z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
gl_FragColor = vec4(vec3((float(i) - log(log(length(z)))) / 64.0), 1);
// The Computer Language Benchmarks Game
// http://benchmarksgame.alioth.debian.org/
//
// contributed by Reed Adams
// *reset*
open System
type Node =

Keybase proof

I hereby claim:

  • I am talyian on github.
  • I am talyian (https://keybase.io/talyian) on keybase.
  • I have a public key ASDR2l3g4aL0kQBiQKSM6P7XXVJNmdC2lz5sYYqMog3DOwo

To claim this, I am signing this object: