Skip to content

Instantly share code, notes, and snippets.

View fedyk's full-sized avatar

Andrii Fedyk fedyk

View GitHub Profile
@fedyk
fedyk / gist:5275772
Created March 30, 2013 07:43
Template of bash
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "$package - attempt to capture frames"
echo " "
echo "$package [options] application [arguments]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-a, --action=ACTION specify an action to use"
@fedyk
fedyk / gist:8147009
Created December 27, 2013 13:40
extend.js
function extend() {
var a = arguments, target = a[0] || {}, i = 1, l = a.length, deep = false, options;
if (typeof target === 'boolean') {
deep = target;
target = a[1] || {};
i = 2;
}
if (typeof target !== 'object' && !isFunction(target)) target = {};
@fedyk
fedyk / Copy text on clipboard
Created January 13, 2014 16:18
JS function to copy text in clipboard.
function copyText (text) {
var div = document.getElementById('__special_copy_div'),
saveSelection,
selection,
rng,
i;
if (!div) {
div = document.createElement('pre');
div.id = '__special_copy_div';
@fedyk
fedyk / gist:8ff1369166c69f6d2380
Created December 12, 2014 14:36
Run cordova(phonegap) app on android device and see all logs.
cordova run android --device && adb logcat *:S CordovaLog:V CordovaWebView:V
@fedyk
fedyk / BaseCollection
Created April 28, 2015 13:00
Like Google Pagination for Backbone.Paginator https://github.com/backbone-paginator/backbone.paginator
Backbone.PageableCollection.extend({
mode: 'server',
state: {
pageSize: 15,
firstPage: 0
},
queryParams: {
pageSize: 'limit',
currentPage: null,
totalPages: null,
@fedyk
fedyk / gist:23761ce1236c5673fb84
Last active August 29, 2015 14:25
Backbone Model fetch error, success and complete events
var ItemModel = Backbone.Model.extend({
// emit fetch:error, fetch:success, fetch:complete, and fetch:start events
fetch: function(options) {
var _this = this;
options = options || {};
var error = options.error;
var success = options.success;
function eventThrottler(callback) {
if (!callback) {
return callback;
}
// @see http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
var requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
@fedyk
fedyk / ngPhone.js
Last active October 24, 2015 18:50
Angular Phone Validation
angular.module('myModule')
.directive('ngPhone', function() {
return {
require: 'ngModel',
link: function(scope, elem, attr, ngModel) {
function isPhone(str) {
var lengths = [7,10,11];
@fedyk
fedyk / nginx.conf
Created May 11, 2016 16:22
Add gzip compressing for nginx
server {
# ...
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
@fedyk
fedyk / bob.js
Created September 7, 2016 11:58
bob(1)(2)(3)(4)...(n) + '' == 1 + 2 + 3 + 4 + ... + n
function bob(val) {
if (this === window) {
return (new bob(val)).factorInc();
}
else {
this.v = val;
}
}
bob.prototype.inc = function(v) {