Skip to content

Instantly share code, notes, and snippets.

William Malo williammalo

Block or report user

Report or block williammalo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@williammalo
williammalo / CircleCircleTangents.glsl
Last active Dec 5, 2016
Find Tangents of Two Circles in glsl, useful for calculating soft shadows https://www.shadertoy.com/view/Mtc3R2
View CircleCircleTangents.glsl
//visual basics code from http://www.vb-helper.com/howto_net_circle_circle_tangents.html ported to glsl
vec4 FindCircleCircleIntersections(vec2 p0, float r0, vec2 p1, float r1){
vec2 dd = p1-p0;
float d = length(dd);
float a = (r0 * r0 - r1 * r1 + d * d) / (2.0 * d);
float h = sqrt(r0 * r0 - a * a);
View README.md

##Object Merger

Recurcively merges two objects.

merge(
  {foo:"foo"},
  {bar:{lol:"lol"}}
);
@williammalo
williammalo / README.md
Last active Oct 8, 2015 — forked from 140bytes/LICENSE.txt
image to 2d array
View README.md

converts canvas image data to a 2d array of booleans

array=img2array(imagedata,width,height)

array[x][y] //gives true or false

very useful for games where you need pixel perfect collision.

Reading an image every time you check for collision is slow. Using a 2d array makes it much faster, and has a very simple syntax (array[x][y]) .

@williammalo
williammalo / README.md
Last active Oct 7, 2015 — forked from 140bytes/LICENSE.txt
masonry under 140bytes
View README.md

A minimalist masonry function

mason(containerElement,brickElement,brickWidth,brickHeight)

Only works with one size of brick.

The only advantage of using this over using inline-block elements is that you can use css transitions.

@williammalo
williammalo / README.md
Last active Mar 1, 2019 — forked from 140bytes/LICENSE.txt
Responsive image loading in 199bytes (minification help needed)
View README.md

This function loops through all images on the page, and serves the appropriately sized image file from a list in a data attribute.

example link: http://total.maloweb.com/responsive

example html:

<img src="default.png" data-widths="400,600,800,1023" data-srcsuffix="-foo.png">

example javascript:

@williammalo
williammalo / README.md
Last active Oct 6, 2015 — forked from 140bytes/LICENSE.txt
get offset of element
View README.md

recursively checks every parent of the element to get the ABSOLUTE offset of the element.

call it like this:

getOff(element).x
getOff(element).y
@williammalo
williammalo / calendar.js
Created Jun 25, 2012
Javascript Calendar Maker
View calendar.js
//function
calendar = function(year,month,template,rowStart,rowEnd,cellStart,cellEnd){
var tmpl=function(a,b){return a.replace(/\{\{([^{}]+)}}/g,function(c,d){return typeof b[d]=="function"?b[d]():b[d]})}
return tmpl(template,{
monthName:"January,February,March,April,May,June,July,August,September,October,November,December".split(",")[month],
year:year,
days:function(f,txt,i){
@williammalo
williammalo / README.md
Last active Oct 6, 2015 — forked from 140bytes/LICENSE.txt
set element properties on nodelists
View README.md

a neat function that allows this:

document.getElementsByTagName('i').innerHTML="pie";

and it will change the innerHTML of all tags AUTOMATICALLY!!!!

incredible!

demo: http://jsfiddle.net/Vw54L/

@williammalo
williammalo / Description.md
Created Jun 19, 2012
Javascript Rss Reader
View Description.md

#Javascript Rss Reader#

Takes a rss feed and prints html (defined by a template) for every post.

@williammalo
williammalo / README.md
Last active Oct 5, 2015 — forked from 140bytes/LICENSE.txt
blockifyIndents
View README.md

Turns indentation into {curly brackets} Great for a yml to json converter or something. Credit to @maettig for writing all* the code.

Turn this:

if(3==3)
    alert("obviously!")
    alert("lol!")

Into:

You can’t perform that action at this time.