Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Shannon Skipper havenwood

:octocat:
View GitHub Profile
View application_helper.rb
module ApplicationHelper
def bell_notification_with_conditional_counter
keyword_arguments = {class: 'notification-bell'}
keyword_arguments[:data] = {count: '...'} if Notification.unread_count(current_user).nonzero?
icon("fas", "bell", **keyword_arguments)
end
end
View x.rb
class Hangman
DICTIONARY = ["cat", "dog", "bootcamp", "pizza"]
def initialize()
@secret_word = Hangman.random_word
@guess_word = Array.new(@guess_word.length, "-")
@attempted_chars = Array.new
@remaining_incorrect_guesses = 5
end
View gvl_release.rb
require 'fiddle'
class GVL
handle = Fiddle::Handle::DEFAULT
address = handle['rb_thread_call_without_gvl']
func = Fiddle::Function.new address, [Fiddle::TYPE_VOIDP,
Fiddle::TYPE_VOIDP,
Fiddle::TYPE_VOIDP,
Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOIDP
View gvl.rb
#!/usr/bin/env ruby
require 'fiddle/import'
module GVLUnlock
extend ::Fiddle::Importer
dlload ::Fiddle::Handle::DEFAULT
FP =
bind 'void *cb(void *data)' do |ptr|
ptr.to_i << 1
@havenwood
havenwood / bench
Last active Jun 6, 2018 — forked from liufengyun/json_benchmark.rb
benchmark for json, yajl and oj.
View bench
~ ruby json_benchmark.rb
String to JSON
Warming up --------------------------------------
Oj.dump 24.918k i/100ms
Yajl.dump 9.461k i/100ms
JSON.dump 24.797k i/100ms
MessagePack.dump 44.355k i/100ms
Calculating -------------------------------------
Oj.dump 267.683k (± 3.4%) i/s - 1.346M in 5.032971s
Yajl.dump 98.929k (± 2.8%) i/s - 501.433k in 5.072850s
View van_laarhoven_lens.rb
# Identity functor that does not give any additional structure
Identity = Struct.new(:value) do
def fmap(func = nil, &blk)
f = func || blk;
Identity.new(f.call(self.value))
end
end
# Const Functor that preserves its content
Const = Struct.new(:value) do
View gist:206989c1fac2de95c5ca1d8ed34f82ec
require 'fiddle'
class Object
def cast(as)
# Make sure iv table of the new class gets initialized.
as.new.send(:instance_variable_set, :@nil, nil)
rbasic = Fiddle::Pointer.new(__id__ << 1)
as_klass = Fiddle::Pointer.new(as.__id__ << 1)
# Ruby guarantees sizeof(VALUE) == sizeof(void *)
@havenwood
havenwood / installfest.md
Last active Oct 21, 2016 — forked from rubydiamond/installfest.md
Requirements to get a sticker and be ready for the workshop day.
View installfest.md

Rails Girls L.A. The Third Level

[ ] I have an editor. It is ___________________.


[ ] I can show you where my terminal is and a few commands.

  • I can show where I am in the directories.
  • List the files in a particular directory.
  • Make a directory.
@havenwood
havenwood / cpus.rb
Created Jun 23, 2016 — forked from parshap/cpus.rb
Determine number of cpu cores to use in Vagrant
View cpus.rb
# Determines how many cpus the virtual machine should be given. Uses half of
# what's available on the host with a default of 4.
def numvcpus
begin
os_cpu_cores / 2
rescue
4
end
end
@havenwood
havenwood / datg
Last active Aug 29, 2015 — forked from 0x0dea/datg
View datg
#!/bin/sh
gem search --no-vers | parallel -j0 -I$ 'curl -O `curl https://rubygems.org/api/v1/gems/$.json | jq -r .gem_uri`'
You can’t perform that action at this time.