Skip to content

Instantly share code, notes, and snippets.

@iCreateJB
iCreateJB / csl.benchmark.rb
Created September 13, 2017 21:01
processing in parallel
Benchmark.ips do |x|
x.report('parallel') do
Parallel.map_with_index(data, in_processes: processes) do |import, i|
processor.import [import.merge(id: i)]
result = processor.render(type, id: i)
result = result.first if type == :bibliography
result
end
end
x.report('without') do
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<% if logged_in? %>
<%= link_to image_tag('logo.png', class: 'img-responsive', alt: 'Honorable'), campaign_path, class: 'navbar-brand' %>
<% else %>
<%= link_to image_tag('logo.png', class: 'img-responsive', alt: 'Honorable'), root_path, class: 'navbar-brand' %>
<% end %>
</div><!-- /navbar-header -->
<div class="navbar-collapse">
def logout
content_tag :li do
content_tag :a, rel: 'nofollow', href: logout_path, 'data-method' => :delete do
concat(content_tag :span, image_tag('icons/icon-log-out', class: 'img-responsive', alt: ''), class: 'icon')
concat(content_tag :span, 'Log Out', class: 'title')
end
end
end
@iCreateJB
iCreateJB / braintree.testing.rb
Created March 27, 2017 15:35
Heroku Braintree Testing.
irb(main):002:0> u = User.find(2492)
User Load (2.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2492 LIMIT 1
User Load (2.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2492 LIMIT 1
=> #<User id: 2492, login: nil, email: "sebastian.lenk+cm303@googlemail.com", crypted_password: "b2a864829cc2cbd63d264c8f9c881295c85d4fe4", salt: "f08a417c0331469b8c9d3972de8b00e8955e89ee", created_at: "2017-03-27 12:52:26", updated_at: "2017-03-27 13:15:51", remember_token: nil, remember_token_expires_at: nil, zipcode: nil, firstname: "", lastname: "", user_type: "", age: nil, password_reset_code: nil, admin: nil, donated_on: nil, age_verification: nil, privacy_policy: nil, disabled: nil, password_digest: nil, subscribed_at: "2017-03-27 12:55:56", chegg_id: "21ffff98-bf0c-4649-a31b-71463af71cc4", chegg_access_token: "HLphgIRLD3XZMakFkC8KlkoylXhY", chegg_refresh_token: nil>
irb(main):003:0> c = Braintree::Customer.find(u.account.braintree_customer_id)
Account Load (1.9ms) SELECT `accounts`.* FROM `ac
@iCreateJB
iCreateJB / braintree_payment.rb
Last active March 6, 2017 21:14
Consolidated Interface to payment services
class BraintreePayment
class << self
def cancel_plan!
end
def charge!
end
def fetch_customer!
@iCreateJB
iCreateJB / bash.output.txt
Created January 25, 2017 13:31
Dockerize easybib/csl-ruby
bash-3.2$ docker build --pull -t chegg/jb .
Sending build context to Docker daemon 1.115 MB
Step 1/12 : FROM ruby:2.2.5-alpine
2.2.5-alpine: Pulling from library/ruby
3690ec4760f9: Pull complete
6353f0aa4196: Pull complete
11cea0b89b81: Pull complete
2fe1fa3442ae: Pull complete
a07dedcb22ec: Pull complete
@iCreateJB
iCreateJB / users_controller.rb
Last active January 6, 2017 13:51
Rescue nesting
def update_email!(new_email:, old_password:)
return true if new_email == @user.email
client = CheggAuthService.client_from_environment
@user.email = new_email
begin
if @user.valid?
client.change_email(access_token: @user.chegg_access_token, new_email: new_email)
@user.save
else
@iCreateJB
iCreateJB / ar_thread_test.rb
Created December 7, 2016 15:18
ActiveRecord Connection Pool with threads
require 'thread'
threads = (0...5).map do
Thread.new
ActiveRecord::Base.connection_pool.with_connection do
user = User.find(1)
user.update_attributes(admin: true)
end
end
end
{"data":{"pubonline":{"title":"Wikipedia","day":"","month":"","year":"","inst":"Wikimedia Foundation","dayaccessed":"21","monthaccessed":"november","yearaccessed":"2016","url":"https://en.wikipedia.org/wiki/Abraham_lincoln"},"website":{"title":"Abraham lincoln"},"contributors":[],"autocite":{"url":"https://en.wikipedia.org/wiki/Abraham_lincoln"},"pubtype":{"main":"pubonline"},"source":"website"},"display":{"page_title":"Wikipedia"}}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" media="all" href="/assets/bibme.css" />
<link rel="stylesheet" media="screen" href="//fonts.googleapis.com/css?family=Asap:400,700" />
<link rel="stylesheet" media="screen" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" />
<script src="http://media.studybreakmedia.com/staging/sbm-bundle-v2.6.0_schema-v3.0.x.js"></script>
<script>