Skip to content

Instantly share code, notes, and snippets.

View khusnetdinov's full-sized avatar
🏠
Working from home

Marat Khusnetdinov khusnetdinov

🏠
Working from home
View GitHub Profile
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
;; `+distribution'. For now available distributions are `spacemacs-base'
;; or `spacemacs'. (default 'spacemacs)
dotspacemacs-distribution 'spacemacs
;; Lazy installation of layers (i.e. layers are installed only when a file
SELECT tablename AS TABLE_NAME,
ROUND(CASE
WHEN otta=0 THEN 0.0
ELSE sml.relpages/otta::numeric
END,1) AS table_bloat,
CASE
WHEN relpages < otta THEN '0'
ELSE pg_size_pretty((bs*(sml.relpages-otta)::bigint)::bigint)
END AS table_waste,
iname AS index_name,
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
@khusnetdinov
khusnetdinov / my_app.ex
Created May 2, 2017 20:58 — forked from alanpeabody/my_app.ex
Websockets in Elixir with Cowboy and Plug
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
Plug.Adapters.Cowboy.child_spec(:http, MyApp.Router, [], [
dispatch: dispatch
])
@khusnetdinov
khusnetdinov / template.ex
Last active December 11, 2016 17:51
Phoenix embed templates
# Embed all defined templates
root = Path.expand("../templates", __DIR__)
for {format, source, _} <- @new ++ @ecto ++ @brunch ++ @html ++ @static ++ @bare do
unless format == :keep do
@external_resource Path.join(root, source)
def render(unquote(source)), do: unquote(File.read!(Path.join(root, source)))
end
end
@khusnetdinov
khusnetdinov / test.rb
Created October 24, 2016 12:20 — forked from servzin/test.rb
class BasketController
def add_to_basket
item = Item.find_by_title(params[:item_title])
basket = $basket
basket.add_item(item)
if basket.count_items > 10
basket.error_messages.add("Слишком много товаров в корзине")
@khusnetdinov
khusnetdinov / Architecture.md
Created October 4, 2016 10:09 — forked from evancz/Architecture.md
Ideas and guidelines for architecting larger applications in Elm to be modular and extensible

Architecture in Elm

This document is a collection of concepts and strategies to make large Elm projects modular and extensible.

We will start by thinking about the structure of signals in our program. Broadly speaking, your application state should live in one big foldp. You will probably merge a bunch of input signals into a single stream of updates. This sounds a bit crazy at first, but it is in the same ballpark as Om or Facebook's Flux. There are a couple major benefits to having a centralized home for your application state:

  1. There is a single source of truth. Traditional approaches force you to write a decent amount of custom and error prone code to synchronize state between many different stateful components. (The state of this widget needs to be synced with the application state, which needs to be synced with some other widget, etc.) By placing all of your state in one location, you eliminate an entire class of bugs in which two components get into inconsistent states. We also think yo
@khusnetdinov
khusnetdinov / heroku-node-init.sh
Created August 28, 2016 20:03 — forked from phatblat/heroku-node-init.sh
Bash script to initialize an OS X box for local development of node app on heroku
#!/bin/bash
NODE_VERSION=0.4.7
NPM_VERSION=1.0.94
# Save script's current directory
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#cd "${DIR}"
#