Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Patricio López Juri lopezjurip

🎯
Focusing
View GitHub Profile
@lopezjurip
lopezjurip / gist:cd92f879bc92af698f85ad0433a953cd
Created Mar 29, 2021
Migrate Postgres string field to integer if present else null
View gist:cd92f879bc92af698f85ad0433a953cd
ALTER TABLE "public"."usage_stats"
ALTER COLUMN "resSize" TYPE INT USING CASE WHEN "resSize" ~ '^[-+0-9]+$' THEN "resSize"::integer ELSE NULL END;
@lopezjurip
lopezjurip / App.tsx
Created Dec 30, 2020
React useReducer useContext with Typescript types
View App.tsx
import React, { useReducer, useContext, Dispatch } from "react";
import "./styles.css";
// Local types, example: box, product, venue, etc
type MyItem = {
id: number;
name: string;
};
// Reducer types
@lopezjurip
lopezjurip / Dockerfile
Last active May 28, 2020
A great Dockerfile for Node.js with Typescript and Yarn (multi-step build) and NPM Token for private modules
View Dockerfile
##
# First stage: prepare image
FROM node:12-alpine AS base
ARG NPM_TOKEN
ARG WORKDIR=/usr/src/app
WORKDIR ${WORKDIR}
# Install container build dependencies
RUN apk --no-cache add g++ ca-certificates lz4-dev musl-dev openssl-dev \
make python gcc zlib-dev libc-dev bsd-compat-headers py-setuptools git bash
@lopezjurip
lopezjurip / gitlab-ci.yml
Created May 23, 2020
pipenv, zappa and Gitlab CI
View gitlab-ci.yml
image: python:latest
stages:
- deploy
variables:
WORKON_HOME: .pipenv/venvs
PIP_CACHE_DIR: .pipenv/pipcache
cache:
@lopezjurip
lopezjurip / css.json
Created May 22, 2020
Flexbox snippet for VSCode. Setup this on the CSS lang so it is available in styled-components etc.
View css.json
{
"Setup basic flexbox styling": {
"prefix": "flex",
"body": [
"display: flex;",
"flex-direction: ${1:column};",
"justify-content: ${2:flex-start};",
"align-items: ${3:flex-start};",
"$0"
],
View apollo-quick-client.js
import { ApolloClient } from "apollo-boost";
import { setContext } from "apollo-link-context";
import { InMemoryCache } from "apollo-cache-inmemory";
export default class APIClient {
constructor(context = {}, options = {}) {
this.context = context;
this.options = { fetchPolicy: "no-cache", ...options };
const authLink = setContext((_, context) => {
return {
View hi.js
console.log("Hello world!");
@lopezjurip
lopezjurip / App.js
Last active Mar 22, 2018
styled-components ssr problems with bad usage
View App.js
/* FOCUS IN THE PURPLE (COOL) <a /> component */
// GOOD ----------------------------------
const Container = styled("div")``;
const Link = styled("a")`
color: green;
`;
const LinkCool = styled(Link)`
color: purple;
`;
@lopezjurip
lopezjurip / lines.sh
Created Jan 10, 2018
Rails 5 - Create seed.rb file from production database in Heroku
View lines.sh
# Download with Heroku CLI
heroku pg:backups:capture
heroku pg:backups:download
# Should create a dump file, let's name it 'latest.dump'
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d MY_APP_development latest.dump
# Install 'seed_dump' gem
bundle exec rake db:seed:dump EXCLUDE=encrypted_password,reset_password_token
View rut.py
import requests
url = 'https://chile.rutificador.com/'
client = requests.session()
client.get(url)
csrftoken = client.cookies['csrftoken']
url = url + 'get_generic_ajax/'