Skip to content

Instantly share code, notes, and snippets.

View diasbruno's full-sized avatar

Bruno Dias diasbruno

View GitHub Profile
@diasbruno
diasbruno / perspectiveToFrustrum
Created May 8, 2012 02:15
perspective to frustum
perspectiveToFrustum( fov, aspectRatio, near, far ) {
tangent = tan( fov/2 * PI / 180 )
height = near * tangent
width = height * aspectRatio
frustum( (left = -width), (right = width), (bottom = -height), (top = height), near, far )
}
/**
* Make a new font face.
*/
.makeFontStyle( @name, @uri, @weight, @style ) {
font-family: @name;
src: url( '@{uri}.eot' );
src: url( '@{uri}.ttf' ) format( 'truetype' );
font-weight: @weight;
font-style: @style;
}
@diasbruno
diasbruno / gist:3324324
Created August 11, 2012 12:59
Load fonts from google fonts CDN.
/**
* Load fonts from google fonts CDN.
* @param $fonts {Array} Array of fonts to be loaded.
* @param $echo {Boolean} If true, print each <link>, else, return an array
* @return {Array} If $echo is true, it will return an empty string.
* @example loadFontFromGoogle( array(
* "Open Sans" => "300,400,600" // font name => thickness
* ));
*/
function loadFontFromGoogle( $fonts, $echo = true ) {
@diasbruno
diasbruno / gist:3914946
Created October 18, 2012 21:46
hold a reference to a function pointer to send to C. inspired by SettableStateVar in Graphics.Rendering.OpenGL.GL.StateVar.
-- Usage
-- setupCallback <* exampleSCBfn
newtype Callback a = Callback (a -> IO ())
type SetupAppCallback = IO ()
infixr 2 <*
(<*) :: Callback a -> SetupAppCallback -> IO ()
@diasbruno
diasbruno / robot.js
Created December 6, 2012 23:36
Tstr
//
// Delete this when available.
//
var Robot=function(r){r.clone();},RP=Robot.prototype;
RP.onIdle=function(e){e.robot.ahead();e.robot.rotateCannon(1);}
RP.onScannedRobot=function(e){e.robot.fire();}
RP.onRobotCollision=
RP.onWallCollision=function(e){e.robot.turn(-90+Math.random()*e.bearing);}
@diasbruno
diasbruno / robot.js
Created December 6, 2012 23:37
Turin
//
// Turin.js 2.0.7b
// @author Bruno Dias
//
// Damn...events should never block!!
// TODO: a lot...
var clone;
var Robot = function(robot) {
this.targetAquired = false;
this.targetX = 0;
@diasbruno
diasbruno / splitAtMatches.hs
Last active December 19, 2015 19:38
splitAtMatches :: Regex -> BL8.ByteString -> [BL8.ByteString] -> IO [BL8.ByteString]
emptyStr :: BL8.ByteString
emptyStr = BL8.pack ""
splitAtMatches :: Regex -> BL8.ByteString -> [BL8.ByteString] -> IO [BL8.ByteString]
splitAtMatches rexp str buf = do
if str == empty then return buf -- if str is empty, we have reached
-- the end or no matches.
else execute rexp str >>=
either (\ (a, b) -> return buf) -- ^ WrapError = (ReturnCode, String)?
(\ a -> case a of -- ^ Array Int (indexOf, length)
@diasbruno
diasbruno / gist:87a5cbed4b52f7848019
Created March 17, 2016 01:13
undefined and NaN
// node
> var a;
undefined
> 1 + a;
NaN
>
@diasbruno
diasbruno / js-funcs
Created November 9, 2016 21:00
before yas snippet
(defun js/anonymous-function ()
(interactive)
(insert "() => {}"))
(defun js/function ()
(interactive)
(insert "function() {}"))
@diasbruno
diasbruno / dos.el
Created November 9, 2016 21:04
dos-like theme for emacs.
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "blue" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 140 :width normal :foundry "nil" :family "Menlo"))))
'(custom-comment-tag ((t (:foreground "gray80"))))
'(flx-highlight-face ((t (:inherit nil :underline t :weight bold))))
'(font-lock-builtin-face ((t (:foreground "white"))))
'(font-lock-comment-face ((t nil)))