Skip to content

Instantly share code, notes, and snippets.

@hoangmy92
hoangmy92 / enum.sql
Created July 26, 2017 06:36 — forked from d11wtq/enum.sql
Renaming an ENUM label in PostgreSQL
/*
Assuming you have an enum type like this.
You want to rename 'pending' to 'lodged'
*/
CREATE TYPE dispute_status AS ENUM('pending', 'resolved', 'open', 'cancelled');
BEGIN;
ALTER TYPE dispute_status ADD VALUE 'lodged';
UPDATE dispute SET status = 'lodged' WHERE status = 'pending';
@hoangmy92
hoangmy92 / ar_migrate.rb
Created March 3, 2017 04:41 — forked from icyleaf/ar_migrate.rb
ActiveRecord type of integer (tinyint, smallint, mediumint, int, bigint)
# activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
@hoangmy92
hoangmy92 / using_meld_on_mac.md
Created November 20, 2016 18:28 — forked from p1nox/using_meld_on_mac.md
Using meld on Mac

Using Meld merging tool on Mac

  1. Install XQuartz

  2. Install meld with brew

     brew install meld
    
  3. Copy PYTHONPATH

@hoangmy92
hoangmy92 / gist:0ec2bd892e21049692aec10221de7586
Created November 19, 2016 09:02 — forked from Amitesh/gist:1160428
Paperclip file name cleanup or rename
#http://blog.wyeworks.com/2009/7/13/paperclip-file-rename
Paperclip.interpolates :default_image_type do |attachment, style|
attachment.instance.get_user_default_profile_image
end
Paperclip.interpolates :normalized_avatar_file_name do |attachment, style|
attachment.instance.normalized_avatar_file_name
end
@hoangmy92
hoangmy92 / yaml_to_tsv.rb
Created September 10, 2016 15:47 — forked from amonmoce/yaml_to_tsv.rb
A Ruby code that convert yaml file into tsv file ... like $ruby yaml_to_tsv.rb in_filename.yml out_filename.tsv; Rubocop tested no offense
# Check the output file
if ARGV[1].nil?
print 'Insert the name of your output file (tsv file) '
outname = $stdin.gets.chomp
else
outname = ARGV[1]
end
# Deserialize
require 'yaml'
survey = YAML.load(File.read(ARGV[0]))
@hoangmy92
hoangmy92 / url_slug.php
Created May 26, 2016 07:35 — forked from sgmurphy/url_slug.php
URL Slugs in PHP (with UTF-8 and Transliteration Support)
<?php
/**
* Create a web friendly URL slug from a string.
*
* Although supported, transliteration is discouraged because
* 1) most web browsers support UTF-8 characters in URLs
* 2) transliteration causes a loss of information
*
* @author Sean Murphy <sean@iamseanmurphy.com>
* @copyright Copyright 2012 Sean Murphy. All rights reserved.