Skip to content

Instantly share code, notes, and snippets.

View styx's full-sized avatar
🌴
¯\_(ツ)_/¯

Mikhail S. Pabalavets styx

🌴
¯\_(ツ)_/¯
View GitHub Profile
@styx
styx / gist:31e2403a70a3b1153bb0
Created February 7, 2016 07:31 — forked from joho/gist:3735740
PostgreSQL 9.2 upgrade steps
Steps to install and run PostgreSQL 9.2 using Homebrew (Mac OS X)
(if you aren't using version 9.1.5, change line 6 with the correct version)
1. launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
2. mv /usr/local/var/postgres /usr/local/var/postgres91
3. brew update
4. brew upgrade postgresql
5. initdb /usr/local/var/postgres -E utf8
6. pg_upgrade -b /usr/local/Cellar/postgresql/9.1.5/bin -B /usr/local/Cellar/postgresql/9.2.0/bin -d /usr/local/var/postgres91 -D /usr/local/var/postgres
7. cp /usr/local/Cellar/postgresql/9.2.0/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
defmodule HttpRequester do
use GenServer.Behaviour
def start_link(_) do
:gen_server.start_link(__MODULE__, nil, [])
end
def fetch(server, url) do
:gen_server.cast(server, {:fetch, url})
end
@styx
styx / 0_reuse_code.js
Created January 10, 2014 12:43
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
require 'spec/support/grep_matcher'
describe do
disallow_presence_of pattern: "send(.*#",
location: "app/",
description: "Do not use dynamic method invocations",
failure: "Please change dynamic method call to something more sane."
end
@styx
styx / gol.exs
Created December 20, 2013 13:14 — forked from avdi/gol.exs
defmodule Life do
def run(board) when is_binary(board) do
board |> parse_board |> run
end
def run(board) do
IO.write("\e[H\e[2J")
Life.print_board board
:timer.sleep 1000
board = next_board(board)
# see http://stackoverflow.com/questions/5880962/how-to-destroy-jobs-enqueued-by-resque-workers - old version
# see https://github.com/defunkt/resque/issues/49
# see http://redis.io/commands - new commands
namespace :resque do
desc "Clear pending tasks"
task :clear => :environment do
queues = Resque.queues
queues.each do |queue_name|
puts "Clearing #{queue_name}..."
defmodule Lab05 do
@doc """
My take on [the histogram exercise]
(http://computing.southern.edu/halterman/Courses/Fall2013/124/Labs/lab05_F13.html)
mentioned in [this newsgroup post]
(https://groups.google.com/d/msg/elixir-lang-talk/TTSjV0iy9yA/hpiGDZOk6DkJ)
"""
def main(), do: parse_pars(System.argv, nil)
defp parse_pars([],nil), do: histogram()
defmodule NumbersInput do
def start do
IO.stream(:stdio, :line)
|> Stream.flat_map(&tokenize/1)
|> Stream.take_while(&(&1 > -1))
end
defp tokenize(line) do
line
|> String.split(" ")
@styx
styx / ipow.ex
Created October 12, 2013 08:40 — forked from alco/ipow.ex
defmodule IntMath do
use Bitwise
def pow(_, 0), do: 1
def pow(a, 1), do: a
def pow(a, n) when band(n, 1) === 0 do
tmp = pow(a, n >>> 1)
tmp * tmp
end
@styx
styx / _output
Created September 24, 2013 19:38 — forked from catsby/_output
$ ls
other_thing.exs
thing.exs
$ elixir thing.exs
calling other
other thing!
hooray!