Skip to content

Instantly share code, notes, and snippets.

function funnyURL(word, interval, prevID) {
prevID = prevID ? prevID : this.prevID; // assume that undefined is OK
clearInterval(prevID);
var i = 0, ID;
ID = setInterval(function() {
history.replaceState(null, '', word.slice(0,i+1));
i = i+1;
if (i >= word.length) clearInterval(ID);
}, interval);
@panych
panych / map.js
Last active August 29, 2015 14:21
Yandex Map image overlay
// 1. Variant. Use existing pane element. Can overlay map objects like placemark, ballons.
// https://tech.yandex.ru/maps/doc/jsapi/2.0/ref/reference/map.pane.Manager-docpage/
map.panes.get('events').getElement().style.backgroundImage = 'my/background/image.png';
// 2. Variant. Create custom element. Pros: set z-index.
var patternEl = document.createElement('div');
patternEl.className = 'map__pattern';
myMap.panes.getInnerElement().appendChild(patternEl);
// then you add styles like:
// .map__pattern {
@panych
panych / server.py
Created May 26, 2015 08:23
Simple Python server
#!/usr/bin/python
"""
(https://snipt.net/raw/f8ef141069c3e7ac7e0134c6b58c25bf/?nice)
Save this file as server.py
>>> python server.py 0.0.0.0 8001
serving on 0.0.0.0:8001
or simply
@panych
panych / snapToPixel.jsx
Last active August 29, 2015 14:21
snapToPixel (Illustrator script)
/*
snapToPixel.jsx
Adobe Illustrator script.
Moves any selected objects to the nearest pixel.
*/
if ( documents.length > 0 ) {
var sourceDoc = activeDocument;
@panych
panych / layout.jade
Created May 20, 2015 12:36
Typical Jade layout
doctype html
<!--[if IE 8]> <html class="lt-ie10 lt-ie9" lang="ru"> <![endif]-->
<!--[if IE 9]> <html class="lt-ie10" lang="ru"> <![endif]-->
<!--[if gt IE 9]><!--> <html lang="ru"> <!--<![endif]-->
head
meta( charset="utf-8" )
meta( http-equiv="X-UA-Compatible" content="IE=edge" )
//- Uncomment it if your site is responsive
//- meta( name="viewport" content="width=device-width, initial-scale=1" )
title Site title
@panych
panych / buildjar.sh
Created May 12, 2015 20:26
Simple jar package builder for IDEA color theme
#!/bin/bash
# Originaly: https://github.com/jkaving/intellij-colors-solarized/blob/master/buildjar.sh
# Create the "colors" directory for the scheme files
# and copy all passed file there
mkdir colors
cp $* colors
# Create an empty "IntelliJ IDEA Global Settings" file,
# needed to be able to import the JAR using "Import Settings..."
@panych
panych / gist:12c342c429088f425430
Last active August 29, 2015 14:20
Get options of select element as JSON
var selectOptionsAsJSON = function(selectEl) {
var result = [], options = selectEl.options;
for (var i=0; i < options.length; i++) {
result.push({"text":options[i].text, "value":options[i].value});
}
window.prompt('Done. Copy text:', JSON.stringify(result));
return result;
}
@panych
panych / app.coffee
Created March 9, 2015 09:05
Make position: fixed useful for horizontal scrolling
# Make position 'fixed' useful for horizontal scroll
$header = $('.header')
$(window).scroll(()->
$header.css('left', "-#{ $(window).scrollLeft() }px")
)
@panych
panych / gist:a0d225a01ddb5f68814b
Created July 17, 2014 09:20
JivoSite open by external link
// Widget documentation http://www.jivosite.ru/javascript-api
function jivo_onLoadCallback() {
$('#online-consultant').addClass('enabled').click(function() {
jivo_api.open();
});
}
// scss
@panych
panych / create_block.rb
Created April 29, 2014 08:04
Create block files (stylesheet, kitchen page, layout)
desc 'Create block stylesheet file and kitchen page'
task :create_block, [:name] do |t, args|
block_name = args[:name]
if block_name == nil
print "Block name is required \n"
else
# TODO Check name for convention validity ('my-super-block', not 'mySuper_block')
# Create stylesheet file
style_file_path = "#{Rails.root}/app/assets/stylesheets/blocks/_#{block_name}.scss"