Skip to content

Instantly share code, notes, and snippets.

View alexeypegov's full-sized avatar
🖖

Alexey Pegov alexeypegov

🖖
View GitHub Profile
@alexeypegov
alexeypegov / avi2m4v.scpt
Created September 4, 2010 17:18
Convert AVI files to M4V (iPhone) one by one using QuickTime Player X
--
-- simple AppleScript to convert chosen AVI files to iPhone video format one by one using QuickTime Player X
--
property outputFolder : (path to movies folder as Unicode text)
on check_exists(fileToCheck)
repeat
tell application "Finder"
if exists file fileToCheck then
exit repeat
@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);
@alexeypegov
alexeypegov / bson.clj
Last active December 23, 2015 19:19
Clojure BSON Reader using Gloss + BSON Binary Search and Fast Document count
(ns ^{:doc "Clojure BSON Reader using Gloss + BSON Binary Search and Fast Document count"
:author "Alexey Pegov"}
bson.gloss
(:require [clojure.java.io :as io])
(:use [gloss core io])
(:import (java.nio BufferUnderflowException)))
; BSON string is a c-style string ended with a \0
(def cstring (string :utf-8 :delimiters [0]))