Skip to content

Instantly share code, notes, and snippets.

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

Mikhail S. Pabalavets styx

🌴
¯\_(ツ)_/¯
View GitHub Profile
[skin]
description=Ajnasz Blue Theme. Midnight Commander skin from Ajnasz.
[Lines]
horiz=─
vert=│
lefttop=┌
righttop=┐
leftbottom=└
rightbottom=┘
source 'http://production.s3.rubygems.org'
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)
@styx
styx / gist:61866912d59bea02a8b0
Last active August 29, 2015 14:13
Deleting duplicates in postgres
-- 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);
#!/usr/bin/env ruby
require 'benchmark/ips'
require "set"
X = (0...10000).sort_by{rand}.take(5000)
Y = (0...10000).sort_by{rand}.take(5000)
SET_X = Set.new(X)
SET_Y = Set.new(Y)
➜ ~ sudo haskell-updater
Running haskell-updater using GHC 7.8.4
* Executable: /usr/bin/ghc
* Library directory: /usr/lib64/ghc-7.8.4
* Package manager (PM): portage
Searching for packages installed with a different version of GHC.
No old packages found!
@styx
styx / elixir.ex
Created May 27, 2015 11:43
Elixir profiling
defmodule Test do
def run do
Enum.each(1..50, &simulated_bottleneck/1)
end
defp simulated_bottleneck(x) do
:timer.sleep(x)
end
end
@styx
styx / active_record_introspection.rb
Created June 1, 2012 05:59 — forked from german/active_record_introspection.rb
adding introspection to all ActiveRecord methods (putting method's name when it's invoked)
module ActiveRecord
Base.singleton_methods.each do |m|
Base.class_eval <<-EOS
class << self
puts "redefining #{m}"
define_method "#{m}_with_introspection" do |*args|
puts "#{m}"
send(:"#{m}_without_introspection", *args)
end
@styx
styx / method_logger.rb
Created September 25, 2012 07:02 — forked from nhance/method_logger.rb
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
Model.new.foo