Skip to content

Instantly share code, notes, and snippets.

View braynm's full-sized avatar

Bry braynm

View GitHub Profile
@braynm
braynm / copy from|to csv.sql
Last active October 18, 2021 07:04
copy from|to csv in postgresql
-- Save without header
copy ((select "name", "email from "user") to '/absolute-path-to-directory/filename.csv' delimiter ',' csv;
-- Save with header
copy ((select "name", "email from "user") to '/absolute-path-to-directory/filename.csv' delimiter ',' csv header;
-- When having issue `must be superuser or a member of pg_write_server_files role COPY to a file`, add a `\` in front of `copy`
\copy ((select "name", "email from "user") to '/absolute-path-to-directory/filename.csv' delimiter ',' csv;
@joshuaalpuerto
joshuaalpuerto / use-api.js
Last active March 27, 2020 10:44
Hooks for requesting api built-in state
import { useReducer, useCallback, useRef, useEffect } from 'react';
import cond from 'lodash/cond';
import includes from 'lodash/fp/includes';
import stubTrue from 'lodash/stubTrue';
const initialState = {
response: null, // could be whatever type of response they are ,expecting
loading: false,
success: false,
error: false,
@iannbing
iannbing / ._reactFormatting
Last active November 15, 2022 17:04
A gist for initial eslint and prettier setup for React projects
We couldn’t find that file to show.
@jswny
jswny / Flexible Dockerized Phoenix Deployments.md
Last active July 3, 2023 05:25
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

@chrismccord
chrismccord / upgrade.md
Last active April 7, 2023 12:03
Phoenix 1.2.x to 1.3.0 Upgrade Instructions

If you want a run-down of the 1.3 changes and the design decisions behidn those changes, check out the LonestarElixir Phoenix 1.3 keynote: https://www.youtube.com/watch?v=tMO28ar0lW8

To use the new phx.new project generator, you can install the archive with the following command:

$ mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez

Bump your phoenix dep

Phoenix v1.3.0 is a backwards compatible release with v1.2.x. To upgrade your existing 1.2.x project, simply bump your phoenix dependency in mix.exs:

@dcarneiro
dcarneiro / sagas.js
Last active November 9, 2023 12:21
connect redux-saga to phoenix channel
function* connectToSocket(url) {
const socket = new Socket(socketBaseUrl() + url, { params: { token: 'your-auth-token' } });
socket.connect();
return socket;
}
// channel.join is async, this is probably an error
function* joinChannel(socket, channel_name) {
const channel = socket.channel(channel_name, {});
channel.join();
@orther
orther / index.js
Created January 27, 2017 17:34
A few simple examples of sorting with Ramda's sortBy function.
import R from 'ramda';
const items = [
{id: 1, name: 'Al', country: 'AA'},
{id: 2, name: 'Connie', country: 'BB'},
{id: 3, name: 'Doug', country: 'CC'},
{id: 4, name: 'Zen', country: 'BB'},
{id: 5, name: 'DatGGboi', country: 'AA'},
{id: 6, name: 'Connie', country: 'AA'},
];
@Integralist
Integralist / Redis vs Memcache.md
Last active February 7, 2024 13:56
Redis vs Memcache

When deciding between Memcached and Redis, here are a few questions to consider:

  • Is object caching your primary goal, for example to offload your database? If so, use Memcached.
  • Are you interested in as simple a caching model as possible? If so, use Memcached.
  • Are you planning on running large cache nodes, and require multithreaded performance with utilization of multiple cores? If so, use Memcached.
  • Do you want the ability to scale your cache horizontally as you grow? If so, use Memcached.
  • Does your app need to atomically increment or decrement counters? If so, use either Redis or Memcached.
  • Are you looking for more advanced data types, such as lists, hashes, and sets? If so, use Redis.
  • Does sorting and ranking datasets in memory help you, such as with leaderboards? If so, use Redis.
  • Are publish a
@jonathantneal
jonathantneal / README.md
Last active February 8, 2024 10:53
Nearest Normal Ratio Calculator

Nearest Normal Aspect Ratio

This function returns the nearest aspect ratio of a width and height within a limited range of possible aspect ratios.

In other words, while 649x360 technically has an aspect ratio of 649:360, it’s often useful to know that the nearest normal aspect ratio is actually 9:5 (648x360).

nearestNormalAspectRatio(width, height, [side], [maxWidth], [maxHeight])
@rubencaro
rubencaro / install_elixir.md
Last active September 30, 2023 03:58
Elixir installation guide

Elixir installation guide

Version numbers should be the ones you want. Here I do it with the last ones available at the moment of writing.

The simplest way to install elixir is using your package manager. Sadly, at the time of writing only Fedora shows the intention to keep its packages up to date. There you can simply sudo dnf install erlang elixir and you are good to go.

Anyway, if you intend to work with several versions of erlang or elixir at the same time, or you are tied to a specific version, you will need to compile it yourself. Then asdf is your best friend.