Skip to content

Instantly share code, notes, and snippets.

@jayuloy
jayuloy / Finding User Sessions with SQL
Created June 25, 2021 06:29 — forked from bstancil/Finding User Sessions with SQL
These queries let you define find user sessions against event data logged to Segment SQL, Snowplow, or Google BigQuery.
-- These queries let you define find user sessions against event data
-- logged to Segment SQL, Snowplow, or Google BigQuery.
-- For more details, see the full post:
-- LINK
--- SEGMENT SQL
-- Finding the start of every session
SELECT *
FROM (
@jayuloy
jayuloy / PostgreSQL_index_naming.rst
Created August 8, 2018 13:45 — forked from popravich/PostgreSQL_index_naming.rst
PostgreSQL index naming convention to remember

The standard names for indexes in PostgreSQL are:

{tablename}_{columnname(s)}_{suffix}

where the suffix is one of the following:

  • pkey for a Primary Key constraint;
  • key for a Unique constraint;
  • excl for an Exclusion constraint;
  • idx for any other kind of index;
@jayuloy
jayuloy / postgres_queries_and_commands.sql
Created July 30, 2017 13:21 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@jayuloy
jayuloy / psqlfix.txt
Created July 25, 2017 11:44
Change postgres default template0 to UTF8 encoding
mike@rbci:~$ psql -U postgres
psql (9.0.3)
Type "help" for help.
postgres=# update pg_database set datallowconn = TRUE where datname = 'template0';
UPDATE 1
postgres=# \c template0
You are now connected to database "template0".
template0=# update pg_database set datistemplate = FALSE where datname = 'template1';
UPDATE 1
@jayuloy
jayuloy / django_image_upload_test.md
Created March 29, 2017 13:48
Django Image Upload & Test

파일 업로드 과정

  1. 사용자가 choose file 버튼을 클릭
  2. 원하는 파일을 선택
  3. upload 버튼을 클릭해 선택한 파일을 전송

( 3.의 과정에서 multipart/form-data을 통해 전송합니다. )

Django model

@jayuloy
jayuloy / upgrade-postgres-9.3-to-9.5.md
Created September 13, 2016 13:18 — forked from johanndt/upgrade-postgres-9.3-to-9.5.md
Upgrading PostgreSQL from 9.3 to 9.5 on Ubuntu

TL;DR

Install Postgres 9.5, and then:

sudo pg_dropcluster 9.5 main --stop
sudo pg_upgradecluster 9.3 main
sudo pg_dropcluster 9.3 main
@jayuloy
jayuloy / 기술 문서를 쓸 때 주의해야 할 몇 가지.md
Created August 14, 2016 08:45 — forked from 9beach/기술 문서를 쓸 때 주의해야 할 몇 가지.md
기술 문서를 쓸 때 주의해야 할 몇 가지를 나열합니다.

기술 문서를 쓸 때 주의해야 할 몇 가지

텍스트 파일의 장점

자신이 하는 일이 소모적인 일회성의 일이 아니라고 여긴다면 위키에 글을 작성해서 보편적인 방식으로 공유하라. 글을 읽고 의문이 생기는 것에 대한 토론은 글 안에서 이루어지는 것이 좋다. 중요한 정보를 위키 혹은 RCS, Git 등으로 관리되는 텍스트가 아닌, 워드, 파워포인트 등의 이진 문서로 작성해서 올릴 때마다 당신의 동료는 그 정보에 대한 접근성, 가시성, 버전 관리 문제로 고통을 겪을 것이다.

명징한 소재

잡다한 소재가 하나의 글에 다 들어가 있으면 재활용성, 접근성, 발전 가능성이 떨어진다. 자기완결적인 항목들로 페이지를 나눔으로써 정보로서의 가치가 더 커진다. 나중에 나눌 의향으로 일단 쓰고 보는 것은 환영한다. 고민 하면서 글쓰기를 미루는 것보다는 일단 쓰는 것이 중요하다.

@jayuloy
jayuloy / GoogleAPI.py
Created June 7, 2016 13:47 — forked from SalvaJ/GoogleAPI.py
Example making HTTP request to use Google API without api-client.It works in Python3 (tested ok in 3.3.5)
#!usr/bin/python3
# -*- coding: UTF-8 -*-
"""This module is a sample of the OAuth2 authentication by Python3"""
__version__ = "0.1.0"
__author__ = "shin (shin.hateblo.jp)"
__copyright__ = "(C) 2012 shin"
__email__ = "s2pch.luck@gmail.com"
__license__ = "Apache License 2.0"
@jayuloy
jayuloy / notes.md
Created January 25, 2016 16:14 — forked from DavidWittman/notes.md
A Brief Introduction to Fabric

A Brief Introduction to Fabric

Fabric is a deployment management framework written in Python which makes remotely managing multiple servers incredibly easy. If you've ever had to issue a change to a group servers, this should look pretty familiar:

for s in $(cat servers.txt); do ssh $s service httpd graceful; done

Fabric improves on this process by providing a suite of functions to run commands on the servers, as well as a number of other features which just aren't possible in a simple for loop. While a working knowledge of Python is helpful when using Fabric, it certainly isn't necessary. This tutorial will cover the steps necessary to get started with the framework and introduce how it can be used to improve on administering groups of servers.

  1. generate an empty migration
  2. move the migration from old_app to new_app
  3. edit the migration file to change all instances of old_app to new_app
  4. add a forward migration to rename the table from something to something_else
  5. add a backward migration to do the opposite
  6. move models.py from old_app to new_app
  7. apply the migration