Skip to content

Instantly share code, notes, and snippets.

@victorpolko
victorpolko / remove-firefox-validation.css
Created Aug 2, 2016
Remove Firefox Input Immediate Validation
View remove-firefox-validation.css
:invalid {
box-shadow: none;
}
:-moz-submit-invalid {
box-shadow: none;
}
:-moz-ui-invalid {
box-shadow:none;
@victorpolko
victorpolko / uniq.simple.js
Last active Sep 11, 2015
JavaScript: unique array values (simple types only)
View uniq.simple.js
var simpleUniq = function(array) {
return array.reduce(function(prev, curr, index, arr) {
if (prev.indexOf(curr) === -1) prev.push(curr);
return prev;
}, []);
}
@victorpolko
victorpolko / duplicates.js
Last active Sep 11, 2015
JavaScript: collect duplicates in array
View duplicates.js
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 / nokogiri_xml_to_hash.rb
Last active Oct 2, 2015
Ruby: Parse Nokogiri XML-node to Ruby Hash instance
View nokogiri_xml_to_hash.rb
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 / deep_struct.rb
Last active Sep 8, 2015
Ruby: deep OpenStruct with hash table
View deep_struct.rb
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 / jquery.scroll-with-speed.coffee
Last active Aug 26, 2015
jQuery plugin for uniform scroll animation
View jquery.scroll-with-speed.coffee
# @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 )
You can’t perform that action at this time.