Skip to content

Instantly share code, notes, and snippets.

View raphaelcosta's full-sized avatar

Raphael Costa raphaelcosta

View GitHub Profile
@hatarist
hatarist / pg_get_table_sizes.sql
Created September 8, 2017 15:48
PostgreSQL: get table size (data & index & toast)
SELECT
*,
pg_size_pretty(table_bytes) AS table,
pg_size_pretty(index_bytes) AS index,
pg_size_pretty(total_bytes) AS total
FROM (
SELECT
*, total_bytes - index_bytes - COALESCE(toast_bytes, 0) AS table_bytes
FROM (
SELECT
@mfd
mfd / GTWalsheimPro.css
Last active May 3, 2024 16:52
GT Walsheim Pro
@font-face {
font-family: GT Walsheim Pro;
src: local("GT Walsheim Pro Regular"),local("GTWalsheimProRegular"),url(GTWalsheimProRegular.woff2) format("woff2"),url(GTWalsheimProRegular.woff) format("woff"),url(GTWalsheimProRegular.ttf) format("truetype");
font-weight: 400;
font-style: normal
}
@font-face {
font-family: GT Walsheim Pro;
src: local("GT Walsheim Pro Bold"),local("GTWalsheimProBold"),url(GTWalsheimProBold.woff2) format("woff2"),url(GTWalsheimProBold.woff) format("woff"),url(GTWalsheimProBold.ttf) format("truetype");
@cooperka
cooperka / ListView to FlatList.diff
Last active June 18, 2020 05:36
Migrating from ListView to FlatList in React Native.
-import { Text, View, ListView } from 'react-native';
+import { Text, View, FlatList } from 'react-native';
import style from './styles';
import listData from './listData';
class App extends Component {
- constructor(props) {
- super(props);
@threepointone
threepointone / infinite.js
Created December 20, 2016 08:44
infinite scrolling pattern with react fiber (featuring intersection observers)
// inifinite scrolling of content without extra wrappers
const { render, findDOMNode } = ReactDOMFiber
class App extends React.Component {
render() {
// wrap the root element with an Intersection Observer, exposing .observe for children
return <Intersection>
<div style={{ height: 200, overflow: 'auto' }}>
<Page offset={0} count={10} />
</div>
@knowbody
knowbody / ex-navigation.md
Last active July 17, 2023 10:14
My exponent's ex-navigation docs/thoughts

Exponent - ex-navigation

This is for now, for my personal use only, things might not be correctly explained here. For the official docs please check: https://github.com/exponentjs/ex-navigation/blob/master/README.md

Navigation bar configuration

On every screen you can use the built-in navigation bar, you can add a title, left button, right button or change navigation bar’s style. All you need to do is pass appropriate params to navigationBar in the route configuration:

import React, { Component } from 'react';
@josevalim
josevalim / watcher.sh
Last active February 28, 2024 07:42
A 1LOC bash script for re-running tests whenever a lib/ or test/ file changes keeping the same VM instance
# You will need fswatch installed (available in homebrew and friends)
# The command below will run tests and wait until fswatch writes something.
# The --stale flag will only run stale entries, it requires Elixir v1.3.
fswatch lib/ test/ | mix test --stale --listen-on-stdin
@dmnsgn
dmnsgn / SingletonDefaultExportInstance.js
Last active February 9, 2023 16:54
ES6 singleton pattern: module default exports an instance
class SingletonDefaultExportInstance {
constructor() {
this._type = 'SingletonDefaultExportInstance';
}
singletonMethod() {
return 'singletonMethod';
}
static staticMethod() {
@rwdaigle
rwdaigle / process.ex
Last active August 29, 2015 14:23
Parallelized collection processing w/ sub-process supervision
alias Task.Supervisor
{:ok, supervisor} = Supervisor.start_link
double = fn(n) -> n*2 end
[1, 2, 3]
|> Enum.map(&Supervisor.async(supervisor, fn -> double.(&1) end))
|> Enum.map(&Task.await/1)
#=> [2, 4, 6]
@CMCDragonkai
CMCDragonkai / http_streaming.md
Last active May 7, 2024 16:35
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on

@kelvinst
kelvinst / i18n-debug.md
Last active August 29, 2015 14:10
Descobrindo as keys de i18n no rails

Descobrindo as keys de i18n no rails

Você já deve ter se pego tentando adivinhar qual key dos arquivos de tradução o rails está buscando né? Chutando as keys uma a uma pra ver se acerta? Não? Bom eu sim 😁, até que eu cansei e procurei algo pra resolver esse problema.

E adivinha só: já existe uma gem pra isso! 🎉 A gem i18n-debug resolve esse problema de uma forma bem fácil. Basta adicionar ela no Gemfile do seu projeto e ele vai começar a colocar as seguintes linhas no log do rails:

[i18n-debug] en.helpers.label.user.username => nil
[i18n-debug] en.helpers.label.user.username => nil
[i18n-debug] en.activerecord.attributes.user.username =&gt; "Username"