Skip to content

Instantly share code, notes, and snippets.

View domgetter's full-sized avatar

Dominic Muller domgetter

View GitHub Profile
vi
automating actions through repetition and composition
with strengths to ubiquity and use through the terminal
"programmable editing"
emacs
extensibility by way of the power of lisp
make the editor do everything that you want in the way you want
make these functionalities easy to put in and pull out
a truly "programmable" editor
colo elflord
require 'chunky_png' # viewable at: http://i.imgur.com/C9Utu2N.png
palette = ["X","O","#","*","o","%","=","-","."]
puts ChunkyPNG::Image.from_file("poke_red.png").pixels.map {|p| p/256 % 256}.each_slice(160).map {|r| r.map {|n| palette[9-n/10*100/256]}.join("") }.join("\n")
=begin
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@domgetter
domgetter / install-tmux
Last active March 15, 2016 01:13 — forked from rothgar/install-tmux
Install tmux 1.9 on rhel/centos 6
# Install tmux on Centos release 6.5
# install deps
yum install gcc kernel-devel make ncurses-devel
# DOWNLOAD SOURCES FOR LIBEVENT AND MAKE AND INSTALL
curl -OL https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -xvzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local
@domgetter
domgetter / maybe_monad.java
Last active February 14, 2016 14:45
An implementation of the Maybe monad in Java for instructional purposes.
import java.util.function.Function;
// Maybe is a monad. Why is it a monad? It is a monad because it:
// A) wraps a value
// B) provides a way of applying functions/calling methods on the wrapped value
// C) always returns an instance of itself when it does this.
class Maybe<T> {
private T value;
public Maybe(T value) {
class Maybe
def initialize(value)
@value = value
end
def map(&block)
Maybe.new(bind &block)
end
def bind
class User
attr_reader :hashed_pass
def initalize
@hashed_pass = ""
end
def change_profile_pic(other_pic)
@profile_pic = other_pic
end
end
db = [{name: "Jim", secret: "I peed my pants.", super_secret: "I love Nickleback."}]
user = {name: "Jim"}
get_secret = -> user { secret = db.find {|db_user| db_user[:name] == user[:name]}[:secret]; user.merge({secret: secret}) }
get_super_secret = -> user { super_secret = db.find {|db_user| db_user[:name] == user[:name]}[:super_secret]; user.merge({super_secret: super_secret}) }
bind = -> x, f { x[:secure] ? f[x[:value]].merge({secure: true}) : x } # security-aware manner of calling functions/methods
unit = -> n { {secure: false, value: n} } # makes objects security-aware
lift = -> f { -> x { unit[f[x]] } } # makes functions/methods security-aware
// Run online: https://eval.in/506636
#include <iostream>
#include <functional>
// curries any function from (int, int) -> int into int -> (int -> int)
auto curry(int (*func)(int, int)) -> std::function<std::function<int (int)> (int)> {
return [func] (int x) {
return [func, x] (int y) {
return func(x, y);
};
irb(main):010:0> Parser::CurrentRuby.parse("\"123\" =~ /1/")
=> (send
(str "123") :=~
(regexp
(str "1")
(regopt)))
irb(main):011:0> Parser::CurrentRuby.parse("\"123\" !=~ /1/")
=> (send
(str "123") :!=
(send