Skip to content

Instantly share code, notes, and snippets.

View kislovskij's full-sized avatar

Viktor Kislovskij kislovskij

  • Leo Burnett Worldwide
  • Frankfurt am Main
View GitHub Profile
@kislovskij
kislovskij / gist:4b170c9e6797f577d87a
Created September 19, 2014 08:15
Algorithm for a balanced photo gallery
viewport_width = $(window).width()
ideal_height = parseInt($(window).height() / 2)
summed_width = photos.reduce ((sum, p) -> sum += p.get('aspect_ratio') * ideal_height), 0
rows = Math.round(summed_width / viewport_width)
if rows < 1
# (2a) Fallback to just standard size
photos.each (photo) -> photo.view.resize parseInt(ideal_height * photo.get('aspect_ratio')), ideal_height
else
# (2b) Distribute photos over rows using the aspect ratio as weight
@kislovskij
kislovskij / [MacOS] Screensaver Installer
Created November 21, 2013 13:10
Installs screensaver depending on screen aspect ratio
#!/bin/sh
cd "$(dirname "$0")"
clear
echo "Installing screensaver ..."
NORMAL_ARCHIVE=files/Mac_Screensaver_QXGA.zip
WIDESCREEN_ARCHIVE=files/Mac_Screensaver_FHD.zip
SCREENSAVER_FILENAME="MyScreensaver.saver"
@kislovskij
kislovskij / high-res-timer-shim.js
Created June 18, 2013 15:23
High resolution timer shim
var now = (function() {
// Returns the number of milliseconds elapsed since either the browser navigationStart event or
// the UNIX epoch, depending on availability.
// Where the browser supports 'performance' we use that as it is more accurate (microsoeconds
// will be returned in the fractional part) and more reliable as it does not rely on the system time.
// Where 'performance' is not available, we will fall back to Date().getTime().
var performance = window.performance || {};
@kislovskij
kislovskij / datenow.js
Created June 18, 2013 13:34
Date.now shim
if (!Date.now) {
Date.now = function now() {
return new Date().getTime();
};
}
@kislovskij
kislovskij / geolocation.js
Created June 18, 2013 13:31
Geo Location shim
// geo-location shim
// currentely only serves lat/long
// depends on jQuery
// doublecheck the ClientLocation results because it may returning null results
;(function(geolocation){
if (geolocation) return;
@kislovskij
kislovskij / requestAnimationFrame.js
Created June 18, 2013 13:31
Request Animation Frame Polyfill
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|| window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)
@kislovskij
kislovskij / opacity.css
Created June 18, 2013 13:25
Opacity Hack
selector {
filter: alpha(opacity=60); /* MSIE/PC */
-moz-opacity: 0.6; /* Mozilla 1.6 and older */
opacity: 0.6;
}
@kislovskij
kislovskij / transparent-png.css
Created June 18, 2013 13:19
Transparent PNG Fix for IE6
.bg {
width:200px;
height:100px;
background: url(/folder/yourimage.png) no-repeat;
_background:none;
_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/folder/yourimage.png',sizingMethod='crop');
}
/* 1px gif method */
@font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff') format('woff'), /* Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
body {
@kislovskij
kislovskij / media-queries.css
Created June 18, 2013 13:16
General Media Queries
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Styles */
}