Skip to content

Instantly share code, notes, and snippets.

View fadeev's full-sized avatar

Denis Fadeev fadeev

View GitHub Profile
@fadeev
fadeev / gist:2486368
Created April 25, 2012 04:31
ANSI Common Lisp (exercises)
;; Exercise 3.2, p. 56
(defun union-in-order (&rest lists)
"Returns a union of lsts, preserving the order"
(remove-duplicates (reduce #'append lists)
:from-end t
:test #'equal))
;; Exercise 3.3, p. 56
(defun sort-by-frequency (list)
"Returns sorted by frequency alist of occurrences,
@fadeev
fadeev / gist:1486429
Created December 16, 2011 15:19
Debian on a Laptop
aptitude install iwlwifi wpasupplicant
In [ /etc/network/interfaces ] add the following:
auto wlan0
iface wlan0 inet dhcp
wpa-ssid [ wireless-network ]
wpa-psk [ password ]
Configure keyboard layout: dpkg-reconfigure keyboard-configuration
@fadeev
fadeev / cons-if.py
Created September 14, 2011 05:21
Cons, car and cdr in Python
def cons(x,y):
return lambda pick: x if pick == 1 else y
def car(cons):
return cons(1)
def cdr(cons):
return cons(2)
@fadeev
fadeev / cons-if.rb
Created September 13, 2011 16:50
Cons, car and cdr in Ruby
def cons a, b
lambda { |pick|
return a if pick == 1
return b if pick == 2
}
end
def car cons
cons.call 1
end
@fadeev
fadeev / cyr_functions.rb
Created September 11, 2011 13:09
Downcase, upcase and “delatin” functions for strings in cyrillic
# encoding: utf-8
class String
def cyr_downcase
self
.unpack("U*")
.map { |c| if (1040..1071) === c then (c + 32) elsif (1025 == c) then 1105 else c end }
.pack("U*")
end
@fadeev
fadeev / gist:1127889
Created August 5, 2011 16:15
Get a single character from the console
# From the Highline gem, https://github.com/JEG2/highline
def get_character( input = STDIN )
raw_no_echo_mode
begin
input.getbyte
ensure
restore_mode
end