Skip to content

Instantly share code, notes, and snippets.

View mateuszkocz's full-sized avatar
✌️

Mateusz Kocz mateuszkocz

✌️
View GitHub Profile
@mateuszkocz
mateuszkocz / moving-in-circle.css
Created February 27, 2012 15:26
Move in a circle without wrapper elements
/**
* Move in a circle without wrapper elements
* Idea by Aryeh Gregor, simplified by Lea Verou
*/
@keyframes rot {
from {
transform: rotate(0deg)
translate(50px)
rotate(0deg);
@mateuszkocz
mateuszkocz / center-with-table-cell.css
Created April 6, 2012 16:34
Centring some element
.wrap {
/* Unimportant styling. */
background-color: #ffa500;
width: 400px;
height: 200px;
/* Solution (part I)*/
/* This code allows element inside the .wrap to be positioned in the middle. */
display: table-cell;
vertical-align: middle;
@mateuszkocz
mateuszkocz / 3d-ball.css
Last active January 22, 2022 23:32
3D ball with CSS radial-gradient
#ball {
width: 300px;
height: 300px; border-radius: 150px;
background-color: blue;
background-image: radial-gradient(circle 400px at 0 0, rgba(0,0,0,0), rgba(0,0,0,0), rgba(0,0,0,.8)), radial-gradient(circle 180px at 90px 80px, rgba(255,255,255,.7), rgba(0,0,0,0));
background-repeat: no-repeat, no-repeat;
position:relative;
}
#ball:after {
@mateuszkocz
mateuszkocz / checkMemory
Created June 15, 2013 11:55
JavaScript debugging function that logs app's memory usage (heap size). Source: Martin Wells (https://gist.github.com/martinwells/2968021)
var lastUsedHeap = 0; // remember the heap size
function checkMemory()
{
// check if the heap size is this cycle is LESS than what we had last
// cycle; if so, then the garbage collector has kicked in
if (window.performance.memory.usedJSHeapSize < lastUsedHeap)
console.log('Garbage collected!');
lastUsedHeap = window.performance.memory.usedJSHeapSize;
@mateuszkocz
mateuszkocz / func-apply
Created June 19, 2013 18:40
Function returning function for convenience. Also Function.prototype.apply(). Source: http://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/
var bind = function(func, thisValue) {
return function() {
return func.apply(thisValue, arguments);
}
}
var boundHello = bind(person.hello, person);
boundHello("world") // "Brendan Eich says hello world"
@mateuszkocz
mateuszkocz / jquery-like-selector
Created June 24, 2013 16:10
jQuery/Sizzle like dollar sign element selector. Source: http://remysharp.com/2013/04/19/i-know-jquery-now-what
var $ = document.querySelectorAll.bind(document);
Element.prototype.on = Element.prototype.addEventListener;
// Instead of this..
if(callback) {
callback();
}
// you can use this.
callback && callback();
function getOffset( el ) {
var offsetTop = 0, offsetLeft = 0;
do {
if ( !isNaN( el.offsetTop ) ) {
offsetTop += el.offsetTop;
}
if ( !isNaN( el.offsetLeft ) ) {
offsetLeft += el.offsetLeft;
}
} while( el = el.offsetParent )
@mateuszkocz
mateuszkocz / css
Created July 19, 2013 19:04
Disable image smoothing. Comes in handy when creating pixel-art game. The pixels will stay sharp.
/* You can aslo add */
canvas {
image-rendering: optimizeSpeed;
image-rendering: -moz-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
-ms-interpolation-mode: nearest-neighbor;
}