Skip to content

Instantly share code, notes, and snippets.

View ovcharik's full-sized avatar

Maksim Ovcharik ovcharik

  • Saint Petersburg, Russia
View GitHub Profile
gen = (cur, all, chunk = 10) ->
half = (chunk - 4) // 2
ledge = Math.max(1 , cur - half)
redge = Math.min(all, cur + half)
ldiff = half - (cur - ledge) + ((ledge < half-1) && 2 || (ledge < half) && 1 || 0)
rdiff = half - (redge - cur) + ((cur+half >= all) && 2 || (cur+half+1 == all) && 1 || 0)
prev = 0
@ovcharik
ovcharik / README.md
Last active February 1, 2017 04:28
Convert markdown text to table of content
@ovcharik
ovcharik / MouseEventDispatcher.js
Created July 2, 2016 14:17
Mouse event dispatcher
;(function() {
"use strict";
/**
* @typedef {Object} MouseEventOptions
* @property {Boolean} canBubble - Whether or not the event can bubble.
* @property {Boolean} cancelable - Whether or not the event's default action can be prevented.
*
* @property {AbstractView} view - The event's AbstractView. You should pass the window object here.
* @property {Number} detail - The event's mouse click count.
@ovcharik
ovcharik / SimpleMutationObserver.class.js
Last active February 27, 2022 12:06
Simple interface for MutationObserver
class SimpleMutationObserver {
constructor(node) {
this.node = node;
this.selectors = {};
this.handlers = {};
this.observer = new MutationObserver(() => {
for (var selector in this.selectors) {
var oldState = this.isEnabled(selector);
var newState = this.checkEnabled(selector);
@ovcharik
ovcharik / grunt-browserify-persistent-cache.coffee
Last active May 4, 2016 20:18
Persistent cache for grunt browserify
fs = require 'fs'
# Structure of cache file:
#
# {
# "path/to/output/file/1": {
# "cache": {
# "path/to/source/file/1": {
# "size" : <file size>,
# "mtime": <file modified time in ms>,
@ovcharik
ovcharik / kinetic_scroll.coffee
Last active November 2, 2016 03:24
Drag and drop scrolling and kinetic animation
(($) ->
$window = $(window)
now = -> (new Date).getTime()
sign = Math.sign ? (v) -> if v > 0 then 1 else (if v < 0 then -1 else 0)
instances = 0
fps = 16
# RAF Polyfill
requestAnimationFrame = window.requestAnimationFrame
cancelAnimationFrame = window.cancelAnimationFrame
@ovcharik
ovcharik / README.md
Last active September 17, 2015 19:44
@ovcharik
ovcharik / createjs.InverseAlphaFilter.coffee
Last active August 29, 2015 14:23
createjs.InverseAlphaFilter.coffee
class InverseAlphaFilter extends createjs.Filter
constructor: ->
toString: ->
return "[InverseAlphaFilter]"
clone: ->
new InverseAlphaFilter
@ovcharik
ovcharik / arc-theme.css
Last active June 22, 2018 20:15
Tilda tab style
notebook > header {
background: #f5f6f7;
border: none;
}
notebook > header > tabs {
background: transparent;
}
notebook > header > tabs > tab {
background: transparent;
color: #8e9195;
@ovcharik
ovcharik / property_mixin.coffee
Created April 28, 2015 06:24
Reactive property mixin for meteor
@PropertyMixin =
property: (prop, options) ->
Object.defineProperty @prototype, prop, options
reactiveProperty: (name) ->
@property name,
get: ->
dep = @["_#{name}_dep"] ?= new Tracker.Dependency
dep.depend()