Skip to content

Instantly share code, notes, and snippets.

@neudabei
neudabei / jekyll1.html
Created June 13, 2015 15:43
jekyll code
---
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 %}
@neudabei
neudabei / jekyll2.html
Created June 13, 2015 15:46
jekyll code
{% for category in page.categories %}
[<a class="post-meta" href="/{{category}}">{{category}}</a>]
{% endfor %}
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
@neudabei
neudabei / portfolio.md
Last active November 30, 2015 12:29
Portfolio
@neudabei
neudabei / use_vanity_controller.rb
Created September 6, 2016 10:03
vanity/test/dummy/app/controllers/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 September 6, 2016 10:05
vanity/test/frameworks/rails/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 22:31
Include live Tweets an email
# 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")
@neudabei
neudabei / verify_proof_of_work.rb
Last active February 17, 2018 10:45
Understanding proof-of-work using Ruby 2 - https://blog.robertsj.com/proof-of-work
require 'digest'
puts Digest::SHA256.hexdigest("hello world!" + "2030350")
@neudabei
neudabei / proof_of_work.rb
Last active February 17, 2018 10:45
Understanding proof-of-work using Ruby - https://blog.robertsj.com/proof-of-work
class ProofOfWork
require 'digest'
def initialize(difficulty:)
@required_number_of_zeros = difficulty
end
def find_nonce_for(block_content:)
nonce = 0
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