Skip to content

Instantly share code, notes, and snippets.

View alexeypegov's full-sized avatar
🖖

Alexey Pegov alexeypegov

🖖
View GitHub Profile
@alexeypegov
alexeypegov / innershadow.js
Created February 13, 2014 20:45
HTML5 Canvas Shadow (Opposite Winding solution)
/* <canvas id="c" width="200" height="200"></canvas> */
function retina(canvas, context) {
var ratio = window.devicePixelRatio || 1,
width = canvas.width,
height = canvas.height;
if (ratio > 1) {
canvas.width = width * ratio;
canvas.height = height * ratio;
canvas.style.width = width + "px";
@alexeypegov
alexeypegov / SheetView.swift
Created November 15, 2014 11:47
SheetView
//
// SheetView.swift
// wrkts
//
// Created by Alexey Pegov on 28.10.14.
// Copyright (c) 2014 alexeypegov. All rights reserved.
//
import UIKit
@alexeypegov
alexeypegov / copy_to_itunes.scpt
Created September 10, 2010 14:33
Folder action to copy files from this folder to "Automatically Add to iTunes" folder
property extension_list : {"mp3"}
property destination_folder : (path to music folder as text) & "iTunes:iTunes Music:Automatically Add to iTunes:"
property this_action_path : (path to home folder as text) & "Library:Scripts:Folder Action Scripts:copy_to_itunes.scpt"
on adding folder items to this_folder after receiving added_items
set number_of_items to 0
repeat with i from 1 to number of items in added_items
set this_file to item i of added_items
if folder of (info for this_file) is true then
tell application "System Events"
@alexeypegov
alexeypegov / youtrack
Created May 12, 2011 10:58
Service to Open selected issue in YouTrack for Google Chrome
(* todo *)
(* trim & validate selected text ^[a-zA-Z]+\-[0-9]+$ *)
(* change menu name to "Open [Selected issue id] in YouTrack" *)
(* multiple browsers support? *)
property theURL : ""
on run {input, parameters}
tell application "Google Chrome"
activate
@alexeypegov
alexeypegov / disposed.jquery.js
Created April 14, 2012 09:20
jquery disposed event to execute some code before element removal
(function ($) {
/**
* Disposer jQuery plugin.
*
* Adds 'disposed' event so you may execute some code _before_ element is somehow removed:
*
* $('.remove').bind('disposed', function() {
* // code to be executed
* });
*
@alexeypegov
alexeypegov / kbd.jquery.js
Created April 14, 2012 09:28
jquery human keyboard handling
// usage: $.initinput(); $.inputmap("pressed LEFT", function() { alert('pressed LEFT') }, null);
// or: $('div').inputmap("pressed ESCAPE", function() { alert('pressed ESCAPE') });
// with $.install_esc_handler() you popups will be closed by ESCAPE. Popups are elements with 'popup' class and 'z-index' > 0
$.extend({
keyCodes:{8:'BACKSPACE', 9:'TAB', 13:'ENTER', 16:'SHIFT', 17:'CONTROL', 18:'ALT', 27:'ESCAPE',
33:'PG_UP', 34:'PG_DN', 35:'END', 36:'HOME', 37:'LEFT', 38:'UP', 39:'RIGHT', 40:'DOWN',
46:'DELETE', 91:'META', 0:'UNKNOWN'},
repeatKeys:[ 37, 38, 39, 40 ],
@alexeypegov
alexeypegov / util.js
Created April 14, 2012 09:28
some handy html gen function & string format extension function
// usage: _('#id.class1.class2[data-b=b]', 'test') -> <div id="id" class="class1 class2" data-b="b">test</div>
// or: _('a.link', {href: 'http://www.example.com'}, 'Click me') -> <a class="link" href="http://www.example.com">Click me</a>
_ = function(text, content_or_attrs, content) {
var result = "", id = false, cls = false, p = false, tag = false;
var b = "";
for (var i = 0; i < text.length; i++) {
var ch = text.charAt(i);
if (ch == '#' && !p) {
@alexeypegov
alexeypegov / pubsub.js
Created May 18, 2012 09:34
Simple Javascript PubSub (observer pattern) AMD-compatible implementation for Loose Coupling
// simple observer (pubsub) implementation
define(["underscore", "base/classex", "util/logging"], function(_, Class, Logging) {
var PubSub = Class.extend({});
PubSub._topics = function() {
if (!window.pubsub) {
window.pubsub = {};
}
return window.pubsub;
@alexeypegov
alexeypegov / browserutil.js
Created May 21, 2012 08:28
Publish event each time browser window is focused/blurred or resized
define(["class", "pubsub"], function(Class, Pubsub) {
var BrowserUtil = Class.extend({
init: function() {
var blur = function onBlur() {
document.body.className = 'blurred';
Pubsub.publish("window:blurred")
};
var gain = function onFocus(){
document.body.className = 'focused';
Upload.initDnD = function () {
var d = $(document)[0];
d.ondragenter = function (event) {
event.preventDefault();
if (!window.drag_in_progress) {
window.drag_in_progress = true;
var drop = $(h('.drop', h('.text', 'Drop it to upload')));
$('body').append(drop);