Skip to content

Instantly share code, notes, and snippets.

View ahvonenj's full-sized avatar
🐢
${framework} solves everything!

Jonah ahvonenj

🐢
${framework} solves everything!
View GitHub Profile
@ahvonenj
ahvonenj / htmlline.js
Last active August 29, 2015 14:23
Drawing lines without canvas, using the HR-tag
function Line(from, to, color, thickness)
{
this.from = from || { x: 0, y: 0 };
this.to = to || { x: 100, y: 100 };
// Aliases for from and to
this.p1 = this.from;
this.p2 = this.to;
this.color = color || 'black';
@ahvonenj
ahvonenj / sineandcosinebetween.js
Last active August 29, 2015 14:23
Sine and cosine wave between two arbitrary values
function sineBetween(min, max, t)
{
var halfRange = (max - min) / 2;
return min + halfRange + Math.sin(t) * halfRange;
}
function cosineBetween(min, max, t)
{
var halfRange = (max - min) / 2;
return min + halfRange + Math.cos(t) * halfRange;
@ahvonenj
ahvonenj / charcode.js
Last active August 29, 2015 14:24
Charcode helpers
function toCharcodes(str)
{
var codestring = '';
var comma = '';
for(var i = 0; i < str.length; i++)
{
comma = (i === str.length-1) ? '' : ',';
codestring += str.charCodeAt(i) + comma;
}
@ahvonenj
ahvonenj / xytable.css
Last active August 29, 2015 14:24
Quick x * y table
*
{
margin: 0;
padding: 0;
}
html, body
{
width: 100%;
height: 100%;
@ahvonenj
ahvonenj / verticalsine.js
Last active August 29, 2015 14:25
Vertical sine wave
// Result: http://puu.sh/j19yl/d37b20ff08.png
this.position =
{
x: self.vpc.x + Math.cos(time * 0.002) * this.helpers.sineBetween(-200, 200, time * 0.02),
y: self.vpc.y + Math.sin(time * 0.002) * this.helpers.sineBetween(200, 200, time * 0.02)
}
this.viewportsize = viewportsize;
this.vpc = { x: this.viewportsize.w / 2, y: this.viewportsize.h / 2 }; // Viewportcenter
@ahvonenj
ahvonenj / sineheart.js
Last active August 29, 2015 14:25
Sine heart
this.position = Victor.fromObject(
{
x: self.vpc.x + Math.cos(time * 0.002) * self.helpers.sineBetween(10, 250, time * 0.002),
y: self.vpc.y + Math.sin(time * 0.002) * self.helpers.sineBetween(-100, 250, time * 0.002)
});
@ahvonenj
ahvonenj / sineball.js
Last active August 29, 2015 14:25
Sine ball
this.position = Victor.fromObject(
{
x: self.vpc.x + Math.cos(time * 0.002) * self.helpers.sineBetween(-100, 100, time * 0.0002),
y: self.vpc.y + Math.sin(time * 0.002) * self.helpers.sineBetween(100, 100, time * 0.002)
});
@ahvonenj
ahvonenj / keycode.js
Last active December 20, 2015 18:44
JavaScript keypress / keycode
$(document).on('keypress', function(e)
{
// Evaluate keycode into a lowercase human-readable letter
var key = String.fromCharCode(e.charCode).toLowerCase();
// Figure what to do with each key
switch(key)
{
case 'a':
console.log('a pressed');
@ahvonenj
ahvonenj / catchajax.js
Created August 10, 2015 09:01
Catch AJAX event / request
$(document).ajaxSend(function(event, request, settings)
{
console.log('Caught AJAX request!');
console.log(event);
console.log(request);
console.log(settings);
});
@ahvonenj
ahvonenj / chromwebstore.js
Created August 26, 2015 15:20
Chrome web store download
/*
* @title crx DL link
* @description prompt crx download-link on Chrome Web Store
* @include https://chrome.google.com/webstore/detail/*
* @contributor taizooo http://let.hatelabo.jp/taizooo/let/gYC-x-e5r_G0bw (Fork of)
* @contributor noromanba http://let.hatelabo.jp/noromanba/let/hLHX5-ST-aMn
* @license MIT License http://opensource.org/licenses/MIT
* @javascript_url
*/