This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateRestaurantService | |
def initialize(owner, restaurant) | |
@owner = owner | |
@restaurant = restaurant | |
end | |
def call | |
@restaurant.user = @owner | |
return false unless @restaurant.valid? | |
@restaurant.save! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder