Skip to content

Instantly share code, notes, and snippets.

View jekyll1.html
---
layout: default
---
<div class="home">
<h1 class="page-heading">Posts in the category [coding]</h1>
<ul class="post-list">
{% for post in site.categories.coding %}
View jekyll2.html
{% for category in page.categories %}
[<a class="post-meta" href="/{{category}}">{{category}}</a>]
{% endfor %}
View sieves_test.rb
require 'minitest/autorun'
require_relative 'sieve_of_eratosthenes'
class SieveTest < Minitest::Test
def test_a_few_primes
expected = [2, 3, 5, 7]
assert_equal expected, Sieve.new(10).primes
end
def test_primes
View portfolio.md
@neudabei
neudabei / use_vanity_controller.rb
Created Sep 6, 2016
vanity/test/dummy/app/controllers/use_vanity_controller.rb
View use_vanity_controller.rb
class UseVanityController < ActionController::Base
class TestModel
def test_method
Vanity.ab_test(:pie_or_cake)
end
end
attr_accessor :current_user
def index
@neudabei
neudabei / action_controller_test.rb
Created Sep 6, 2016
vanity/test/frameworks/rails/action_controller_test.rb
View action_controller_test.rb
require "test_helper"
class UseVanityControllerTest < ActionController::TestCase
tests UseVanityController
def setup
super
metric :sugar_high
new_ab_test :pie_or_cake do
metrics :sugar_high
@neudabei
neudabei / live_tweets_in_email.rb
Created May 31, 2015
Include live Tweets an email
View live_tweets_in_email.rb
# This code is based on the explanations by Kevin Thompson (http://kevinthompson.info/) here https://gist.github.com/kevinthompson/c3023df8e2c904ad00d9
# See the email here: http://www.mailerbob.com/live-tweets/email.html
require 'sinatra'
require 'twitter'
helpers do
def twitter
@twitter ||= Twitter::REST::Client.new do |config|
config.consumer_key = ENV.fetch("TWITTER_CONSUMER_KEY")
View verify_proof_of_work.rb
require 'digest'
puts Digest::SHA256.hexdigest("hello world!" + "2030350")
@neudabei
neudabei / proof_of_work.rb
Last active Feb 17, 2018
Understanding proof-of-work using Ruby - https://blog.robertsj.com/proof-of-work
View proof_of_work.rb
class ProofOfWork
require 'digest'
def initialize(difficulty:)
@required_number_of_zeros = difficulty
end
def find_nonce_for(block_content:)
nonce = 0
View subject_category_interest_props.rb
def subject_category_interest_props
subject_categories = SubjectCategory.in_alphabetical_order
interested_subject_categories = current_user.interested_subject_categories
{ fields:
subject_categories.map do |sc|
selected = interested_subject_categories.include?(sc)
{ title: sc.title, value: sc.id.to_s, selected: selected }
end }
end