Skip to content

Instantly share code, notes, and snippets.

defmodule BlogPostApp.Router do
use BlogPostApp.Web, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
class CreateRestaurantService
def initialize(owner, restaurant)
@owner = owner
@restaurant = restaurant
end
def call
@restaurant.user = @owner
return false unless @restaurant.valid?
@restaurant.save!
@azranel
azranel / scrapper.rb
Created October 22, 2015 13:51
Scrapper
require 'nokogiri'
require 'open-uri'
require 'pry'
file_name = "./filtered_addresses.txt"
File.open(file_name) do |file|
file.each do |address|
uri = URI.escape(address.chomp)
doc = Nokogiri::HTML(open(uri))
@azranel
azranel / filter.rb
Last active October 22, 2015 13:50
sitemap_filter
files = Dir["./*.xml"]
files.each do |file_path|
File.open(file_path) do |file|
file.each do |line|
next unless line.start_with? "<loc>"
next unless line.match /view\/emoji\//
puts line.chars[5..-8].join('')
end
end
n, t = 8, [5,6,7,8]
k, u = t.size - 1, t.clone
i = k
while (i >= 0) && (t[i]==n-k+i) do i = i - 1 end
if i != -1
for j in (i..k)
u[j] = t[i]+1+j-i
def unrank(ranga, n)
return (ranga%2).to_s if n==1
m = 2**(n-1)
if ranga < m
return '0' + unrank(ranga, n-1)
end
return '1' + unrank(m - (ranga % m) - 1, n - 1)
end
r, n = 5, 3
r, b, n, t = 0, 0, 3, [2,3]
(n-1).downto(0) do |i|
b = 1 - b if t.include?(n-i)
r = r + 2**i if b==1
end
puts r.to_s