Skip to content

Instantly share code, notes, and snippets.

judofyr / fizzbuzz.rb
Created August 1, 2012 21:37 — forked from JEG2/fizzbuzz.rb
Writing FizzBuzz with flip-flops
a=b=c=(1..100).each do |num|
print num, ?\r,
("Fizz" unless (a = !a) .. (a = !a)),
("Buzz" unless (b = !b) ... !((c = !c) .. (c = !c))),
judofyr /
Last active December 8, 2023 11:12
Brainfuck macro in Rust
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>>,
judofyr /
Created July 3, 2016 18:13
Example of reflection in C++
#define REFLECT(x) template<class R> void reflect(R& r) { r x; }
#include <string>
struct Person {
std::string name;
int age;
("name", name)
function mvim() {
if [ -d "$1" ]; then
local dir=$(printf %q "$1")
command mvim --cmd ":cd $dir" "$@"
command mvim "$@"
judofyr / lazy.scm
Created July 29, 2013 15:02
Lazy lists without closures in Scheme
#lang r5rs
; A lazy list is a cons of two values: a head (a value) and a tail,
; a lambda that returns other lazy list. It's very easy to create a
; closure-based implementation:
(define (lazy-from n)
(cons n (lambda () (lazy-from (+ 1 n)))))
(define (lazy-head lst) (car lst))
(define (lazy-tail lst) ((cdr lst)))
# /app/components/link_as_button.rb
class LinkAsButton
attr_reader :href
attr_reader :disabled
def initialize(
disabled: false,
judofyr / example.txt
Created December 14, 2018 07:31
Tests and code in same file
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 / minify_html.rb
Created September 12, 2018 13:28
Example of using Nokogiri to minify HTML
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)
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)
require_relative 'parser'
class Arithmetic
include ParserCombinators
def root
def expression
require_relative 'import'
B = import "b"
p defined?(::User)
user = B.new_user
p user