Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonas Nicklas jnicklas

View GitHub Profile
@jnicklas
jnicklas / konami.ts
Created Apr 20, 2021 — forked from cowboyd/konami.ts
Konami Code detector written in effection
View konami.ts
import { run } from 'effection';
import { once } from '@effection/events';
run(function*() {
yield konamiCodeEntered();
alert('99 lives!');
});
function * konamiCodeEntered() {
while (true) {
View lolruby.rb
class Client
attr_reader :key,
def initialize(key)
@key = key
end
end
Client.new("moo") # results in: ArgumentError: wrong number of arguments (given 1, expected 0)
View test.md
  • Feature Name: throwing_functions
  • Start Date: 2017-06-20
  • RFC PR: (leave this empty)
  • Rust Issue: (leave this empty)

Summary

Add an annotation to functions that they may "throw" an error type, which changes the function's return type to Result<T, E> where T is the functions return type and E is the function's

View asyncRepl.js
const vm = require('vm');
const repl = require('repl');
function myEval(cmd, context, filename, callback) {
let result;
try {
result = vm.runInContext(cmd, context);
} catch (e) {
return callback(e);
}
View test.rb
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"
View option1.rb
describe "My page" do
it "lists the item" do
item = create_item
within item_row(item) do
expect(page).to mention_item(item)
end
end
private
View repro.rb
require "capybara"
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
sess = Capybara::Session.new(:selenium, app)
sess.visit("/")
sess.click_link("Click me")
sess.reset!
View Gemfile
source "http://rubygems.org"
ruby "2.3.0"
gem "selenium-webdriver"
gem "capybara", "2.7.0"
View request_blocker_middleware.rb
# Prevents requests from hitting the Rails app after the test has finished.
class CapybaraRequestBlockerMiddleware
# assignment to initialized instance variables is thread safe in Ruby
@enabled = false
class << self
def enabled?
@enabled
end
View error.txt
Compiling graphers v0.1.0 (file:///Users/jonasnicklas/Projects/graphers)
src/parse/grammar.rs:390:13: 390:60 error: unreachable pattern [E0001]
src/parse/grammar.rs:390 Some((__loc1, Tok::Identifier(__tok0), __loc2)) => {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/parse/grammar.rs:390:13: 390:60 help: run `rustc --explain E0001` to see a detailed explanation
src/parse/grammar.rs:438:13: 438:60 error: unreachable pattern [E0001]
src/parse/grammar.rs:438 Some((__loc1, Tok::Identifier(__tok0), __loc2)) => {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/parse/grammar.rs:438:13: 438:60 help: run `rustc --explain E0001` to see a detailed explanation
src/parse/grammar.rs:481:13: 481:45 error: unreachable pattern [E0001]