Skip to content

Instantly share code, notes, and snippets.

View citizen428's full-sized avatar

Michael Kohl citizen428

View GitHub Profile
@citizen428
citizen428 / zip_with.rb
Created November 22, 2011 20:46
Haskell's zip_with in Ruby
def zip_with(other, op=nil)
return [] if self.empty? || other.empty?
clipped = self[0..other.length-1]
zipped = clipped.zip(other)
if op
zipped.map { |a, b| a.send(op, b) }
else
zipped.map { |a, b| yield(a,b) }
end
end
@citizen428
citizen428 / ruby_github.rb
Created November 23, 2011 19:33
Create an Atom feed from the new Ruby repos page
require 'open-uri'
require 'nokogiri'
require 'builder'
html = open("https://github.com/languages/Ruby/created")
doc = Nokogiri::HTML.parse(html)
atom = Builder::XmlMarkup.new(:target => STDOUT, :indent => 2)
atom.instruct!
atom.feed "xmlns" => "http://www.w3.org/2005/Atom" do
@citizen428
citizen428 / forth.rb
Last active September 29, 2015 23:58
NotReallyFORTH
class Proc
def prim_call(stack)
forth_arity = self.arity - 1
if stack.size < forth_arity
puts "Buffer underrun"
return stack.clear
end
forth_arity > 0 ? self.call(stack, *stack.pop(forth_arity)) : call(stack)
end
end
@citizen428
citizen428 / with.rb
Created March 21, 2012 12:30
ActionScript-like "with" for Ruby, result of SO discussion
module Kernel
def with(obj, &block)
obj.instance_eval &block
obj
end
end
@citizen428
citizen428 / userContent.css
Created January 16, 2014 20:42
Get rid of the "Inland" section of http://derstandard.at. Place contents of this file in `chrome/userContent.css` inside your Firefox profile directory.
@-moz-document url(http://derstandard.at/) {
div.section.inland { display: none }
}
loop { print ">> " ; puts("=> %s" % eval(gets.chomp!)) }
@citizen428
citizen428 / fizzbuzz.ex
Last active August 29, 2015 14:10
Elixir FizzBuzz server
defmodule FizzBuzz do
def compute do
receive do
n -> IO.puts compute(n)
end
compute
end
defp compute(n) do
case {rem(n, 3), rem(n, 5)} do
#
# A colorful, friendly, multiline theme with some handy features.
# Based on the 'giddie' theme by Paul Gideon Dann.
#
# Authors:
# Michael Kohl <[email protected]>
# Paul Gideon Dann <[email protected]>
# Sorin Ionescu <[email protected]>
#
# Features:
@citizen428
citizen428 / array_extension.swift
Last active January 26, 2016 17:22
Turning Swift into Ruby
import Foundation
extension Array {
func each(task: (Element) -> ()) {
for element in self {
task(element)
}
}
func eachWithIndex(start: Int? = nil, task: (Int, Element) -> ()) {
@citizen428
citizen428 / even_numbers_sequence.swift
Last active January 13, 2016 07:34
Swift sequences, generators etc
class EvenNumbers: CollectionType {
let startIndex : Int
let endIndex : Int
init(start: Int, end: Int) {
self.startIndex = start
self.endIndex = end
}
convenience init() {