Skip to content

Instantly share code, notes, and snippets.

View vol4ok's full-sized avatar

Andrew Volkov vol4ok

View GitHub Profile
@vol4ok
vol4ok / gist:9364446
Last active August 29, 2015 13:57
on ng-repeat finish directive for angular js
angular.module("app").directive("onRepeatFinish", ["$timeout", function($timeout){
return {
restrict: "A",
link: function($scope, $element, $attrs) {
if ($scope.$last) {
$timeout(function(){
if (angular.isFunction($scope[$attrs["onRepeatFinish"]]))
$scope[$attrs["onRepeatFinish"]]()
});
}
@vol4ok
vol4ok / gist:fc094e5f95ea5c89c5bb
Last active August 29, 2015 14:01
route all to angular grunt config
var modRewrite = require('connect-modrewrite');
//...
// initConfig -> Connect section
livereload: {
options: {
open: true,
base: [
'.tmp',
@vol4ok
vol4ok / echoHttpRequest.js
Last active August 29, 2015 14:20 — forked from Marak/echoHttpRequest.js
Echo HTTP requests
module['exports'] = function echoHttp (hook) {
hook.debug("Debug messages are sent to the debug console");
hook.debug(hook.params);
hook.debug(hook.req.path);
hook.debug(hook.req.method);
@vol4ok
vol4ok / HTML(Rails)
Created August 22, 2011 08:08
CoffeeBeans tag syntax highlight for textmate
{ scopeName = 'text.html.ruby';
fileTypes = ( 'rhtml', 'erb', 'html.erb' );
foldingStartMarker = '(?x)
(<(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)\b.*?>
|<!--(?!.*-->)
|\{\s*($|\?>\s*$|//|/\*(.*\*/\s*$|(?!.*?\*/)))
)';
foldingStopMarker = '(?x)
(</(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)>
|^\s*-->
@vol4ok
vol4ok / gist:1524333
Created December 27, 2011 16:51
Recursive ID3 convert CP1251 to Unicode
require 'rubygems'
require 'id3lib'
require 'iconv'
def encode (filename)
puts "encode #{filename}"
tag = ID3Lib::Tag.new(filename)
for f in tag
if f[:text]
f[:text] = Iconv.conv('UTF-16BE','CP1251',f[:text])
@vol4ok
vol4ok / restart.c
Created February 10, 2012 06:44
restart root nginx
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
int result;
setuid( 0 );
result = system("/bin/bash -c 'kill -HUP `cat /usr/local/var/run/nginx.pid`'");
@vol4ok
vol4ok / stylus.tmsyntax
Created February 11, 2012 12:09
My TextMate syntax for stylus
{ scopeName = 'source.stylus';
fileTypes = ( 'styl', 'stylus' );
patterns = (
{ name = 'comment.line.stylus';
match = '(?:^[ \t]+)?(\/\/).*$\n?';
captures = { 1 = { name = 'punctuation.definition.comment.stylus'; }; };
},
{ name = 'comment.block.stylus';
begin = '/\*';
end = '\*/';
@vol4ok
vol4ok / create_github_repo.sh
Created May 11, 2012 06:52
create github repo from shell
curl -u "YOUR_USERNAME" https://api.github.com/user/repos -d '{"name":"MY NEW REPO","description":"REPO DESCRIPTION", "private": false}'
@vol4ok
vol4ok / chain.js
Created October 18, 2012 14:08
chain
$.chain = function() {
var tasks
, args = []
, error = noop;
if(arguments.length === 3) {
args = $.isArray(arguments[0]) ? arguments[0] : [arguments[0]];
tasks = arguments[1];
error = arguments[2];
} else if(arguments.length === 2) {
@vol4ok
vol4ok / gist:4249910
Created December 10, 2012 10:46
getStartOfWeek
DAY = 86400000
getStartOfWeek = (t) ->
UTC3_OFFSET = 60*60*3
kDays4Years = [0, 365, 2 * 365, 3 * 365 + 1]
kDaysIn4Years = 4 * 365 + 1
kDaysIn100Years = 25 * kDaysIn4Years - 1
kDaysIn400Years = 4 * kDaysIn100Years + 1
kDays1970to2000 = 30 * 365 + 7
kDaysOffset = 1000 * kDaysIn400Years + 5 * kDaysIn400Years - kDays1970to2000
kYearsOffset = 400000