Skip to content

Instantly share code, notes, and snippets.

View mateuszkocz's full-sized avatar
✌️

Mateusz Kocz mateuszkocz

✌️
View GitHub Profile
@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 / 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 / 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 / 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 / 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);