Skip to content

Instantly share code, notes, and snippets.

@pumbur
pumbur / av.c
Created October 25, 2018 17:49
// glfw + libao + libav*: video player outline.
// too simple for a real video player, too complex for a libav demo. (ffmpeg has it's own ways to output, see libavdevice/*)
// gcc av.c -o av -lav{util,format,codec,util} -lsw{scale,resample} -l{ao,epoxy,glfw,pthread}
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <stdio.h>
@pumbur
pumbur / mathness.rb
Last active December 22, 2018 10:03
require 'madness' # https://gist.github.com/pumbur/2df08af2ad846ace75fa
need 'prime', 'bigdecimal/math', 'matrix'
{:prm=>Prime,:mth=>Math,:vec=>Vector,:mat=>Matrix}.each{|n,k| Kernel.class_alias(n,k) }
Num.act :sqrt, ->{ Math.sqrt(self) },
:cbrt, ->{ Math.cbrt(self) },
:sin, ->{ Math.sin(self) },
:cos, ->{ Math.cos(self) },
@pumbur
pumbur / madness.rb
Last active December 22, 2018 09:51
class Object
def main?; (TOPLEVEL_BINDING.eval('self')==self) rescue (self.inspect=='main') end
def main_eval(&b); (main? ? Kernel : self).module_eval(&b); end
def aka(q); main_eval{ q.each{|k,v| alias_method(k,v) }}; end
def act(*q); main_eval{ q.each_slice(2){|a,b| define_method(a,&b) }}; end
def slf(*q); main_eval{ q.each_slice(2){|a,b| define_singleton_method(a,&b) }}; end
def to_sym; to_s.to_sym; end
def self; self; end
end
@pumbur
pumbur / common.rb
Last active August 29, 2015 13:57
henna origin
require 'pp'
require 'oj'
class Object
def ary?; self.is_a?(Array); end
def hsh?; self.is_a?(Hash); end
def sym?; self.is_a?(Symbol); end
def str?; self.is_a?(String); end
def prc?; self.is_a?(Proc); end
def num?; self.is_a?(Numeric); end