Skip to content

Instantly share code, notes, and snippets.

View anaumov's full-sized avatar
🚀
Looking for an interesting project related to real life.

Alexey Naumov anaumov

🚀
Looking for an interesting project related to real life.
View GitHub Profile
@anaumov
anaumov / validate_xml.rb
Created December 3, 2012 06:39
Ruby xml validator
# -*- coding: utf-8 -*-
class RssFeedValidator < ActiveModel::EachValidator
def validates_each(record, attribute, value)
feed = Curl::Easy.new(url) do|curl|
curl.on_success validate_xml(feed, record, attribute)
curl.on_failure record.errors[attribute] << "remote host not avalible."
end
end
def validate_xml(feed, record, attribute)
# -*- coding: utf-8 -*-
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
begin
m = Mail::Address.new(value)
r = m.domain && m.address == value
t = m.__send__(:tree)
r &&= (t.domain.dot_atom_text.elements.size > 1)
rescue Exception => e
r = false
@anaumov
anaumov / ffmpeg installation
Last active December 22, 2015 08:59
Debain install ffmpeg
$ sudo apt-get install subversion git cmake build-essential yasm libqt4-dev kdelibs5-dev libsdl1.2-dev libsdl-image1.2-dev libxml2-dev libx264-dev libtheora-dev libxvidcore-dev libogg-dev libvorbis-dev libschroedinger-dev libmp3lame-dev libfaac-dev libfaad-dev libgsm1-dev libopencore-amrnb-dev libopencore-amrwb-dev libsamplerate0-dev libjack-dev libsox-dev ladspa-sdk swh-plugins libmad0-dev libpango1.0-dev
Add the following line to /etc/apt/sources.list:
deb http://www.deb-multimedia.org squeeze main
$ sudo apt-get update
$ sudo apt-get install deb-multimedia-keyring
$ sudo apt-get install libfaac-dev
@anaumov
anaumov / deploy
Created September 27, 2013 05:19
deploy to vps
ssh root@host_ip
# если perl выдает ошибки с локалью
$ locale
$ export VAR='value'
$ apt-get update
$ apt-get -y install curl git-core python-software-properties
$ sudo apt-get install build-essential zlib1g-dev curl git-core sqlite3 libsqlite3-dev
@anaumov
anaumov / .rails_deploy
Last active January 1, 2016 08:59
deploy rails app
IP Address: somehost
Username: root
Password: root_password
ssh root@somehost
# if perl display errors aboul locale
locale
export LC_ALL="en_US.UTF-8"
@anaumov
anaumov / gist:8432161
Created January 15, 2014 07:18
sample ActiveSupport::Configurable
class CarConfig
include ActiveSupport::Configurable
config_accessor :brand
end
class Car
attr_accessor :brand
def initialize
self.brand = self.class.config.brand
@anaumov
anaumov / inline_edit.html
Created October 15, 2015 10:52
Инлайн редактирование
<div ng-repeat="tour in tours">
<h1 ng-show="tour.state=='view'">{{tour.title}}</h1>
<input ng-show="tour.state=='edit'" ng-model="title" />
<button ng-click="editTour(tour)" ng-show="tour.state=='view'">Редактировать</button>
<button ng-click="saveTour(tour)" ng-show="tour.state=='edit'">Сохранить</button>
<button ng-click="cancelEditing(tour)" ng-show="tour.state=='edit'">Отменить</button>
</div>
@anaumov
anaumov / promises.js
Created October 28, 2015 07:50
Использование промисов
function loadCountries(){
$http.get('http://api.com/countries')
}
var allCountries = [];
// летит запрос на сервер, ждем ответа, после ответа заполняем массив
loadCountries().then(function(data){
allCountries = data.countries
})
@anaumov
anaumov / autoclose.js
Created December 18, 2015 15:06
AutoClose Directive
export function AutocloseDirective ($document, $timeout) {
'ngInject';
let directive = {
restrict: 'A',
scope: { visible: "=mdAutoclose" },
link: (scope) => {
let close = () => {
scope.$apply(() => {scope.visible = false;});
};
@anaumov
anaumov / password_log.rb
Created January 10, 2016 08:18
Cleanup password for logs
class User
def test message
if block_given?
yield(message)
else
message
end
end
end