Skip to content

Instantly share code, notes, and snippets.

View onedal's full-sized avatar
🎯
Focusing

mega6obep onedal

🎯
Focusing
  • Russia
View GitHub Profile
@onedal
onedal / epars.rb
Last active August 29, 2015 14:17
Нахождение много url-ов
def parsing_links(url)
hrefs = (connect(url)).css("a").map do |link|
if (href = link.attr("href")) && !href.empty?
URI::join(url, href)
end
end.compact.uniq
puts hrefs.size
return [*hrefs] # Так всегда возращаться массив
end
@onedal
onedal / through_mvc.rb
Last active October 18, 2015 08:57
has_many :through with as foreign_key
# class Bip < ActiveRecord::Base
has_many :comments, foreign_key: 'bid'
has_many :users, through: :comments, foreign_key: 'bid'
# class User < ActiveRecord::Base
has_many :comments, foreign_key: 'uid'
has_many :bips, through: :comments, foreign_key: 'uid'
#class Comment < ActiveRecord::Base
belongs_to :user, foreign_key: 'uid'
@onedal
onedal / authentication_with_bcrypt_in_rails_4.md
Last active October 10, 2015 05:39 — forked from thebucknerlife/authentication_with_bcrypt_in_rails_4.md
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

# Auto check mirrorlist
sudo pacman-mirrors -g
sudo pacman -S os-prober
sudo grub-mkconfig -o /boot/grub/grub.cfg
# Полезные проги
yaourt -S sublime-text-nightly
yaourt -S hipchat
yaourt -S google-chrome
@onedal
onedal / ubuntu.sh
Last active January 14, 2016 09:54
Ubuntu deploy
# Ruby on rails
https://gorails.com/setup/ubuntu/14.04
https://wixelhq.com/blog/how-to-install-postgresql-on-ubuntu-remote-access
sudo apt-get install libpq-dev
sudo apt-get install imagemagick
sudo apt-get install libmysqlclient-dev
sudo apt-get install mysql-server
@onedal
onedal / logger.rb
Created January 3, 2016 11:27
logger.rb
# Пример использования лога #cat log2.txt |grep ERROR
require 'logger'
class MyLog
def self.log
@onedal
onedal / whenever.rb
Created January 3, 2016 11:29
whenever.rb
# Use this file to easily define all of your cron jobs.
#
# It's helpful, but not entirely necessary to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron
# Example:
#
# set :output, "/path/to/my/cron_log.log"
#
# every 2.hours do
@onedal
onedal / redis.rb
Created January 3, 2016 11:31
redis.rb
require 'redis'
require 'json'
redis = Redis.new(:host => "localhost", :port => 6379, :db => 0)
# Ключ - значение
redis.set("mykey", "hello worlds")
#.zshrc
export PATH="$PATH:/usr/bin:/usr/local/bin/"
# Если не видит ruby,rake, bundler
# sudo gem install bundler --no-user-install
class Twitter::Client
def initialize(token, secret)
@client = ::Twitter::REST::Client.new do |config|
config.consumer_key = Rails.application.secrets.twitter_api_key
config.consumer_secret = Rails.application.secrets.twitter_api_secret
config.access_token = token
config.access_token_secret = secret
end