Skip to content

Instantly share code, notes, and snippets.

Magnus Holm judofyr

Block or report user

Report or block judofyr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View tubby_genral_compopent_reuse.rb
# /app/components/link_as_button.rb
class LinkAsButton
attr_reader :href
attr_reader :disabled
def initialize(
href:,
disabled: false,
&blk,
)
@judofyr
judofyr / example.txt
Created Dec 14, 2018
Tests and code in same file
View example.txt
minitest-same-file $ ruby fib.rb
minitest-same-file $ ruby -rminitest/autorun fib.rb
Run options: --seed 15401
# Running:
.
Finished in 0.000960s, 1041.6668 runs/s, 1041.6668 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
@judofyr
judofyr / minify_html.rb
Created Sep 12, 2018
Example of using Nokogiri to minify HTML
View minify_html.rb
require 'nokogiri'
def minify_html(html)
doc = Nokogiri::HTML.parse(html)
doc.xpath('//comment()').each { |comment| comment.remove }
doc.to_html(save_with: Nokogiri::XML::Node::SaveOptions::AS_HTML)
end
html_code = '<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Bla bla bla</title></head><body><p>Abc <!--stuff to remove--></p></body></html>'
puts minify_html(html_code)
View arith.rb
require_relative 'parser'
class Arithmetic
include ParserCombinators
def root
expression
end
def expression
View a.rb
require_relative 'import'
B = import "b"
p defined?(::User)
user = B.new_user
p user
@judofyr
judofyr / json.cc
Created Jul 3, 2016
Example of reflection in C++
View json.cc
#define REFLECT(x) template<class R> void reflect(R& r) { r x; }
#include <string>
struct Person {
std::string name;
int age;
REFLECT(
("name", name)
@judofyr
judofyr / bf.rs
Last active Jun 6, 2016
Brainfuck macro in Rust
View bf.rs
#![recursion_limit="100"]
use std::io;
use std::io::{Write, Read};
use std::num::Wrapping;
struct Tape<'a> {
stdin: &'a mut Read,
stdout: &'a mut Write,
data: Vec<Wrapping<u8>>,
View update-gh-pages.sh
set -e
DIR="docs"
BRANCH="gh-pages"
# Stage all files in the directory
find "$DIR" -type f | xargs git update-index --add
# Write the sub-tree
TREE=$(git write-tree --prefix="$DIR")
View mbug.nim
type Foo = distinct int
template `&`(a: Foo, b: Foo): expr =
debugEcho "anding"
const x = a
Foo(int(a) + int(b))
echo int(Foo(1) & Foo(2) & Foo(3) & Foo(4) & Foo(5))
@judofyr
judofyr / a.md
Created Apr 22, 2014
Patch for Ruby 2.1.1
View a.md
ruby-install -p https://gist.githubusercontent.com/judofyr/11175629/raw/2f22144e3ca261e9e989fcb9a205b473c208007f/patch.diff ruby 2.1.1
You can’t perform that action at this time.