Skip to content

Instantly share code, notes, and snippets.

Avatar
🌴
¯\_(ツ)_/¯

Mikhail S. Pabalavets styx

🌴
¯\_(ツ)_/¯
View GitHub Profile
@styx
styx / gist:61866912d59bea02a8b0
Last active Aug 29, 2015
Deleting duplicates in postgres
View gist:61866912d59bea02a8b0
-- A frequent question in IRC is how to delete rows that are duplicates over a set of columns, keeping only the one with the lowest ID.
-- This query does that for all rows of tablename having the same column1, column2, and column3.
DELETE FROM tablename
WHERE id IN (SELECT id
FROM (SELECT id,
row_number() over (partition BY column1, column2, column3 ORDER BY id) AS rnum
FROM tablename) t
WHERE t.rnum > 1);
View gist:ea8760a47c8f13cac6fa
defmodule Curried do
defmacro defc({name, _, args}, [do: body]) do
curried_args = Enum.map(Enum.with_index(args), fn({_, index}) ->
Enum.take(args, index + 1)
end)
for a <- curried_args do
if a == Enum.at(curried_args, Enum.count(curried_args) - 1) do
quote do
def unquote(name)(unquote_splicing(a)) do
unquote(body)
View Gemfile
source 'http://production.s3.rubygems.org'
View ajnasz-blue.ini
[skin]
description=Ajnasz Blue Theme. Midnight Commander skin from Ajnasz.
[Lines]
horiz=─
vert=│
lefttop=┌
righttop=┐
leftbottom=└
rightbottom=┘
@styx
styx / gist:beb1aa5210c3afb45fd9
Created Dec 12, 2014
Disable a task in production environment
View gist:beb1aa5210c3afb45fd9
DISABLED_TASKS = [
'db:drop',
'db:migrate:reset',
'db:schema:load',
'db:seed',
# ...
]
namespace :db do
desc "Disable a task in production environment"
View warnings
test/eex_test.exs:213: warning: missing specification for function 'test respects line number inside middle expressions with keywords'/1
test/eex_test.exs:235: warning: missing specification for function 'test properly handle functions'/1
test/eex_test.exs:255: warning: missing specification for function 'test do not consider already finished functions'/1
test/eex_test.exs:275: warning: missing specification for function 'test evaluates nested do expressions'/1
test/eex_test.exs:290: warning: missing specification for function 'test for comprehensions'/1
test/eex_test.exs:299: warning: missing specification for function 'test unicode'/1
test/eex_test.exs:308: warning: missing specification for function 'test evaluates the source from a given file'/1
test/eex_test.exs:314: warning: missing specification for function 'test evaluates the source from a given file with bindings'/1
test/eex_test.exs:320: warning: missing specification for function 'test raises an Exception when there\'s an error with the given file
@styx
styx / gist:43a44e1b536ddf7c76bd
Created Nov 12, 2014
Assets in Rails console
View gist:43a44e1b536ddf7c76bd
Rails.application.assets.find_asset('mail.css').body
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
include ActionView::Helpers::AssetTagHelper
@styx
styx / gist:e512d89217d922b8f7bb
Created Nov 12, 2014
Setup Jenkins user in Gerrit
View gist:e512d89217d922b8f7bb
#!/bin/bash
cat ./id_rsa.pub | ssh -p 29418 styx.mp@192.168.11.11 gerrit create-account --ssh-key - jenkins --full-name "Leeroy\ Jenkins" --email jenkins@domain.com
View nginx.conf
user www-data;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
View fib_with_agents.exs
defmodule FibAgent do
defstruct cache: nil, highest_n: 0
def start_link do
initial_cache = Enum.into([ {0, 0}, {1, 1}], HashDict.new)
state = %__MODULE__{cache: initial_cache, highest_n: 1}
Agent.start_link(fn -> state end, name: __MODULE__)
end