Skip to content

Instantly share code, notes, and snippets.

@mmagm
mmagm / smb.conf
Created December 15, 2011 20:02
Samba config
[global]
realm = mma-laptop
# Workgroup = имя NT-домена (или рабочей группы):
workgroup = WORKGROUP
# NetBIOS-имя, под которым будет виден сервер остальным машинам сети.
netbios name = NAU
# Комментарий, появляющийся рядом с именем машины в "Сетевом окружении" Windows.
server string = mma-laptop-samba
@mmagm
mmagm / zshrc
Created April 9, 2012 12:11
zshrc backup config
#!/bin/zsh
HISTFILE=~/.histfile
HISTSIZE=1000000
SAVEHIST=100000
bindkey -e
# completion
autoload -U compinit
compinit
@mmagm
mmagm / merge-sort.rb
Created May 12, 2012 14:08
merge sort
class Array
def self.split(array)
left = []
right = []
length = array.length
if length.odd?
left = array.first(length / 2 + 1)
else
left = array.first(length / 2)
end
@mmagm
mmagm / insertion-sort.rb
Created May 12, 2012 14:31
insertion sort
class Array
def insertion_sort_imperative
self.each_index do |j|
v = self[j]
i = j - 1
while (i >= 0) and (self[i] > v) do
self[i], self[i + 1] = self[i + 1], self[i]
i = i - 1
end
self[i + 1] = v
@mmagm
mmagm / merge-sort.hs
Created May 12, 2012 16:50
haskell merge sort
import Data.List
merge :: Ord a => [a] -> [a] -> [a]
merge x [] = x
merge [] y = y
merge (x:xs) (y:ys) = case compare x y of
LT -> x : merge xs (y:ys)
_ -> y : merge (x:xs) ys
mergesort :: Ord a => [a] -> [a]
@mmagm
mmagm / bubble-sort.hs
Created May 12, 2012 17:38
bubble sort
import Data.List
bubble :: Ord a => [a] -> [a]
bubble [] = []
bubble [x] = [x]
bubble (x:x':xs) = case compare x x' of
GT -> x' : bubble (x:xs)
_ -> x : bubble (x':xs)
bubblesort :: Ord a => [a] -> [a]
class Array
def left(i)
2 * i + 1
end
def right(i)
2 * i + 2
end
def heapify(i, heapsize)
@mmagm
mmagm / heap-sort.hs
Last active February 2, 2018 07:21
haskell heap sort
import Data.List
swap :: Int -> Int -> [a] -> [a]
swap i j xs | i == j = xs
swap i j xs | otherwise = initial ++ (xs !! b) : middle ++ (xs !! a) : end
where [a,b] = sort [i,j]
initial = take a xs
middle = take (b-a-1) (drop (a+1) xs)
end = drop (b+1) xs
@mmagm
mmagm / pqueue.rb
Created May 15, 2012 07:59
priority queue
class PQueue
def initialize
@a = []
@heapsize = 0
end
def left(i)
2 * i + 1
end
@mmagm
mmagm / quick-sort.hs
Created May 15, 2012 09:36
haskell quick sort
qsort :: Ord a => [a] -> [a]
qsort [] = []
qsort (x:xs) = qsort lesser ++ [x] ++ qsort greater
where
lesser = filter (< x) xs
greater = filter (>= x) xs