Skip to content

Instantly share code, notes, and snippets.

@victorpolko
victorpolko / jquery.scroll-with-speed.coffee
Last active August 26, 2015 17:01
jQuery plugin for uniform scroll animation
# @param [jQuery Object] target Dom element to scroll to
# @param [Integer] speed Speed (pixels per second)
$.fn.scrollWithSpeed = (target, speed = 10000, easing, complete) ->
@stop().animate(
scrollTop: target.offset().top
, Math.abs($(window).scrollTop() - target.offset().top) / speed * 1000
, easing
, complete )
@victorpolko
victorpolko / deep_struct.rb
Last active September 8, 2015 15:06
Ruby: deep OpenStruct with hash table
class DeepStruct < OpenStruct
def initialize(hash = nil)
check_hash = lambda { |entry| entry.is_a?(Hash) ? self.class.new(entry) : entry }
@table = {}
@hash_table = {}
hash.try(:each) do |key, val|
if val.is_a?(Array)
other = Array.new
@victorpolko
victorpolko / nokogiri_xml_to_hash.rb
Last active October 2, 2015 14:08
Ruby: Parse Nokogiri XML-node to Ruby Hash instance
nokogiri_xml_to_hash = lambda do |node|
out_hash = {}
return out_hash if node.nil?
node.attributes.each { |k,_| out_hash[k] = node.attr(k) }
node.elements.try(:each) do |elem|
prop = nokogiri_xml_to_hash(elem)
if prop.is_a?(Array) && prop.size > 1
@victorpolko
victorpolko / duplicates.js
Last active September 11, 2015 14:50
JavaScript: collect duplicates in array
var duplicates = function(array) {
var iteratee = array.slice(0);
var seen = [];
return array.filter(function(element) {
iteratee.shift();
if (seen.indexOf(element) !== -1) return false;
var hit = iteratee.indexOf(element) !== -1;
if (hit && seen.indexOf(element) === -1) seen.push(element);
@victorpolko
victorpolko / uniq.simple.js
Last active September 11, 2015 14:50
JavaScript: unique array values (simple types only)
var simpleUniq = function(array) {
return array.reduce(function(prev, curr, index, arr) {
if (prev.indexOf(curr) === -1) prev.push(curr);
return prev;
}, []);
}
@victorpolko
victorpolko / remove-firefox-validation.css
Created August 2, 2016 09:09
Remove Firefox Input Immediate Validation
:invalid {
box-shadow: none;
}
:-moz-submit-invalid {
box-shadow: none;
}
:-moz-ui-invalid {
box-shadow:none;
@victorpolko
victorpolko / gist:463a2188237341d4b5139d492ad0e5f3
Created February 2, 2021 17:20
Quick notes in browser using contenteditable
data:text/html, <html contenteditable><head><title>::Quick Notes::</title><script>window.onbeforeunload=function(e){return e.returnValue=true};</script></head><body><ol><li></li></ol></body></html>