Skip to content

Instantly share code, notes, and snippets.

@sinslav
sinslav / gist:4cd01ee1cc4c22c0eb5f85c0aa36459f
Created April 19, 2016 11:42
backbone file validation
File = Backbone.Model.extend
validate: (args) ->
result
if [email protected](args)
result = 'File already in list'
result
Files = Backbone.Collection.extend
model: File
function processURL(url, success){
var id;
if (url.indexOf('youtube.com') > -1) {
id = url.split('/')[1].split('v=')[1].split('&')[0];
return processYouTube(id);
} else if (url.indexOf('youtu.be') > -1) {
id = url.split('/')[1];
return processYouTube(id);
} else if (url.indexOf('vimeo.com') > -1) {
function throttle(func, ms) {
var isThrottled = false,
savedArgs,
savedThis;
function wrapper() {
if (isThrottled) { // (2)
savedArgs = arguments;
$.fn.textWidth = (text, font) ->
if (!$.fn.textWidth.fakeEl)
$.fn.textWidth.fakeEl = $('<span>').css("white-space", "pre").hide().appendTo(document.body)
$.fn.textWidth.fakeEl.text(text or this.val() or this.text()).css('font', font or this.css('font'))
return $.fn.textWidth.fakeEl.width()
window.uniClick = if (document.ontouchstart isnt null) then 'click' else 'touchstart'
@sinslav
sinslav / object-watch.js
Created October 23, 2015 10:06 — forked from eligrey/object-watch.js
object.watch polyfill in ES5
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
@sinslav
sinslav / gist:d9fb377143417c812d72
Created July 31, 2015 16:05
CSS -> component position righ side of centred block element
//styles
.abs
position absolute
.abs-helper
position relative
white-space nowrap
.abs
top 0
var valuta, sum, uah_kurs, usd_kurs, eur_kurs;
uah_kurs=1;
usd_kurs=1/28;
eur_kurs=1/32;
valuta=prompt('Какую валюту вы хотите обменять? \(usd\, uah или eur\)');
// if (valuta !== 'usd' || 'USD' || 'uah' || 'UAH' || 'EUR' ||'eur') {alert('Введите валюту в формате USD, UAH или EUR')};
sum=+prompt('Сколько у вас валюты?');
switch(valuta) {
case 'usd'||'USD': {alert('Ваши ' + sum + ' ' + valuta + ' равны ' + sum/usd_kurs + ' uah ' + ' или ' + sum/usd_kurs * eur_kurs + ' eur'); break;}
case 'uah'||'UAH': {alert('Ваши ' + sum + ' ' + valuta + ' равны ' + sum*usd_kurs + ' usd ' + ' или ' + sum*eur_kurs + ' eur' ); break;}
@sinslav
sinslav / gist:7d623ba0c7bd99940d4b
Created June 30, 2015 13:21
functional fizzbuzz
function fizzbuzz (counter) {
if ((counter % 5 === 0) && (counter % 3 === 0)) return 'fizzbuzz';
if (counter % 3 === 0) return 'fizz';
if (counter % 5 === 0) return 'buzz';
return counter;
}
function consl () {
for (var i = 1; i <= 100; i++){
console.log(fizzbuzz(i));
@sinslav
sinslav / rAF.js
Last active August 29, 2015 14:23 — forked from paulirish/rAF.js
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];