Skip to content

Instantly share code, notes, and snippets.

View alco's full-sized avatar
🇺🇦

Oleksii Sholik alco

🇺🇦
View GitHub Profile
@alco
alco / brew-clisp.log.sh
Created April 4, 2011 20:14
The full log of an unsuccessful clisp installation with Homebrew
~ $ brew install clisp
==> Downloading http://ftp.gnu.org/pub/gnu/clisp/release/2.49/clisp-2.49.tar.bz2
File already downloaded and cached to /Users/sholik/Library/Caches/Homebrew
==> ./configure --prefix=/usr/local/Cellar/clisp/2.49 --with-readline=yes
executing /private/tmp/homebrew-clisp-2.49-folP/clisp-2.49/src/configure --prefix=/usr/local/Cellar/clisp/2.49 --with-readline=yes
configure: creating cache config.cache
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... build-aux/install-sh -c -d
checking for gawk... no
@alco
alco / brew-clisp-another.log.sh
Created April 4, 2011 20:55
A second attemp at building clisp
~ $ brew link libsigsegv
Linking /usr/local/Cellar/libsigsegv/2.8... 2 links created
~ $ brew install clisp
==> Downloading http://ftp.gnu.org/pub/gnu/clisp/release/2.49/clisp-2.49.tar.bz2
File already downloaded and cached to /Users/sholik/Library/Caches/Homebrew
==> ./configure --prefix=/usr/local/Cellar/clisp/2.49 --with-readline=yes
==> ulimit -s 16384 && make
==> make check
==> make install
mkdir -p gllib
@alco
alco / regex.cc
Created February 20, 2012 14:39
A presumably simple abstraction over regex engines
#include "regex.h"
using namespace boost::xpressive;
struct regex_t {
sregex pattern;
};
@alco
alco / glob_match.cc
Created February 20, 2012 14:41
A translation of Python's fnmatch function into C++
#include <string>
#include "regex.h"
/*
* Return a new string with all occurrences of 'from' replaced with 'to'
*/
std::string replace_all(const std::string &str, const char *from, const char *to)
{
std::string result(str);
@alco
alco / replace_all.cc
Created February 20, 2012 14:43
replace_all function in standard C++
#include <string>
#include <iostream>
#include <assert.h>
std::string replace_all(const std::string &str, const char *from, const char *to)
{
std::string result(str);
std::string::size_type
index = 0,
from_len = strlen(from),
@alco
alco / mergesort.clj
Created March 20, 2012 13:08
Mergesort in Clojure
(defn merge-seqs
"Merges two sorted sequences into a single sorted sequence"
([left right]
(merge-seqs (list left right)))
([[left right]]
(loop [l left, r right, result []]
(let [lhead (first l), rhead (first r)]
(cond
(nil? lhead) (concat result r)
(nil? rhead) (concat result l)
@alco
alco / gist:2165064
Created March 22, 2012 22:20
Count the number of non-blank SLOC in an Elixir project
git ls-files | egrep '\.erl|\.ex[s]$' | xargs cat | sed '/^$/d' | wc -l
@alco
alco / sample output
Created March 27, 2012 23:56
Updated Elixir chat demo
# !!!
# This is an outdated version of the code. See https://gist.github.com/2783092.
defmodule Chat.Client do
# In all of the following functions 'server' stands for the server's pid
def join(server) do
send server, :join
end
def say(server, message) do
@alco
alco / gist:2252662
Created March 30, 2012 16:33
A handy `with` macro
defmodule With do
@doc """
Provides a shortcut for multiple function invocations on the same module.
Example:
x = [1,2,3,4]
with List do
@append [x, @reverse x]
end
@alco
alco / gist:2301410
Created April 4, 2012 14:13
A handy macro for replacing vars with atoms and vice versa
defmodule Atomize do
@doc """
Given an expression, replaces all variables with atoms and atoms with
variables.
For example,
a = 1; b = "string"
Atomize.invert {a, :a, {{b, :b}, [c, d]}}
#=> {:a, 1, {{:b, "string"}, [:c, :d]}}