Skip to content

Instantly share code, notes, and snippets.

View radar's full-sized avatar

Ryan Bigg radar

View GitHub Profile
@radar
radar / Controller
Created January 30, 2017 04:38 — forked from crova/Controller
How to run this task with delayed_job
# fetchs SIB Account information
def sib_account_fetch
sib = Mailin.new("API_URL","API_KEY")
acct = sib.get_account()
acct.dig('data')
credits = acct.dig('data', 0).to_h
SibAccount.find(1).update_attributes(credits)
details = acct.dig('data', 2).to_h
SibAccount.find(1).update_attributes(details).delay
require 'rubygems'
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(open("http://v-tac.eu/led-lights/lights1/led-spotlights/led-spotlight-7w-gu10-smd-white-plastic-white-detail.html"))
puts page.class # => Nokogiri::HTML::Document
fields = page.css(".product-field-type-S")
fields.each do |field|
key = field.css(".product-fields-title").text
@radar
radar / models.rb
Created January 25, 2017 04:31 — forked from mfifth/models.rb
class User < ActiveRecord::Base
has_many :groups
end
class Group < ActiveRecord::Base
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
def self.my_where(key, value)
# Normally with 2 arguments, you can easily do:
where(key: value)
end
def self.where_preference(conditions)
# But with a map and several k-v pairs, you'd have to do something like
conditions.inject(self) do |scope, (k, v)|
scope.where(k => v)
@radar
radar / Gemfile
Last active November 9, 2016 22:18 — forked from lynnfaraday/en.yml
Illustrating i18n issue
source 'https://rubygems.org'
gem "pry"
gem 'i18n', github: "svenfuchs/i18n", branch: "173-reset-load-path"
gem "rspec"
h = { outer: { inner: [1, 2, 3] } }
h[:outer][:inner] = h[:outer][:inner].map(&:to_s)
module UserHelpers
def new_user
user = Fabricate(:user)
session[:user_id] = user.id
end
def current_user
User.find(session[:user_id])
end
@radar
radar / tetris_board.ex
Last active December 18, 2015 05:02 — forked from jakenotjacob/tetris_board.ex
First attempt at... elixir.
board = List.flatten(Enum.map(?a..?j, fn x ->
Enum.map(?0..?9, fn y ->
{String.to_atom(<< x, y >>), nil}
end)
end))
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name,:password,:password_confirmation,:email) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name,:password,:password_confirmation,:email) }
end
module DashboardHelper
def sedex_status(sedex)
if sedex.ts_signature.nil?
if Time.now - sedex.ts_print <= 1.hour
"Cinza"
else
"Vermelho"
end
elsif sedex.ts_print - sedex.ts_signature > 1.hour
"Amarela"