Skip to content

Instantly share code, notes, and snippets.

Avatar
🌴
¯\_(ツ)_/¯

Mikhail S. Pabalavets styx

🌴
¯\_(ツ)_/¯
View GitHub Profile
View README.md

Reduce boilerplate in Redux

  • Create actions similar to Flummox.
  • Generate action ids.
  • Supports actions with decorators, promises, and therefore ES7 async.
@styx
styx / demo.ex
Last active Nov 23, 2016
demo.ex
View demo.ex
def reply(%Nadia.Model.Update{
message: %Nadia.Model.Message{
chat: %Nadia.Model.Chat{id: chat_id, type: type},
text: text}})
do
@styx
styx / Links.txt
Created Apr 18, 2016 — forked from iBublik/Links.txt
Useful links
View Links.txt
@styx
styx / gist:31e2403a70a3b1153bb0
Created Feb 7, 2016 — forked from joho/gist:3735740
PostgreSQL 9.2 upgrade steps
View gist:31e2403a70a3b1153bb0
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/
@styx
styx / elixir.ex
Created May 27, 2015
Elixir profiling
View elixir.ex
defmodule Test do
def run do
Enum.each(1..50, &simulated_bottleneck/1)
end
defp simulated_bottleneck(x) do
:timer.sleep(x)
end
end
View gist:e566ed83ce8f7cc91db9
View bench_rails_memory_usage.rb
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
View gist:e2ab6a400721406691af
~ 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!
View gist:3d8a23250d899a53791f
#!/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)
@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);