Skip to content

Instantly share code, notes, and snippets.

View nnasoody's full-sized avatar

Nima Nasoody nnasoody

  • LumiQ
  • San Francisco
View GitHub Profile
@nnasoody
nnasoody / statistics.sql
Created August 28, 2020 16:50 — forked from ruckus/statistics.sql
Postgres statistics queries
** Find commmonly accessed tables and their use of indexes:
SELECT relname,seq_tup_read,idx_tup_fetch,cast(idx_tup_fetch AS numeric) / (idx_tup_fetch + seq_tup_read) AS idx_tup_pct FROM pg_stat_user_tables WHERE (idx_tup_fetch + seq_tup_read)>0 ORDER BY idx_tup_pct;
Returns output like:
relname | seq_tup_read | idx_tup_fetch | idx_tup_pct
----------------------+--------------+---------------+------------------------
schema_migrations | 817 | 0 | 0.00000000000000000000
user_device_photos | 349 | 0 | 0.00000000000000000000
@nnasoody
nnasoody / psql_useful_stat_queries.sql
Created August 28, 2020 16:47 — forked from anvk/psql_useful_stat_queries.sql
List of some useful Stat Queries for PSQL
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB.
------------
-- Basics --
------------
-- Get indexes of tables
@nnasoody
nnasoody / twitter_stream.ex
Created March 14, 2020 22:23 — forked from mgwidmann/twitter_stream.ex
Infinite Streams with Elixir
# Elixir has lazily evaluated enumerable objects that allow you
# to work with enumerable objects like lists either only as needed
# or infinitely.
# Start up iex to play around
$ iex
# Typical enumeration is done eagerly where the result is computed ASAP
iex> Enum.map(1..10, fn i -> i * 2 end)
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
$ mix new policy_enforcement_playground
$ cd policy_enforcement_playground
# Make a new file lib/authorization.ex
defmodule Authorization do
def authorize_first_thing(_user, resource) do
# Do some authorization here, modifying what gets returned based on the
# authorization level of the user
resource
end
@nnasoody
nnasoody / while.ex
Created March 14, 2020 21:42 — forked from mgwidmann/while.ex
An example of metaprogramming, extending the Elixir language, to add the while keyword. Taken from Chris McCord's example in his Metaprogramming Elixir book.
# The Elixir language is very extensible to allow for future additions or
# third party developers to take the language in directions that the original
# authors could not predict.
#
# Lets start with understanding what an Elixir macro is
iex> quote do
...> 1 + 1
...> end
{:+, [context: Elixir, import: Kernel], [1, 1]}
begin;
/*
* Get a list of 200
*/
create view bak.ed_renewals_for_zeus as
select user_id,
rxcui,
subscription_id,
@nnasoody
nnasoody / postgres-cheatsheet.md
Created January 8, 2018 03:29 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@nnasoody
nnasoody / postgres cheatsheet.md
Created November 30, 2017 02:26 — forked from apolloclark/postgres cheatsheet.md
postgres cheatsheet

Postgres Cheatsheet

This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.

Setup

installation, Ubuntu

http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL

@nnasoody
nnasoody / what-forces-layout.md
Created October 18, 2017 00:49 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
Request URL:https://8wdfb4bdpl.execute-api.us-west-2.amazonaws.com/beta/rpc/login
Request Method:POST
Status Code:400
Remote Address:54.192.136.194:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
access-control-allow-headers:Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token
access-control-allow-methods:DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT
access-control-allow-origin:*