Skip to content

Instantly share code, notes, and snippets.

@jheth
jheth / table_size.sql
Created November 2, 2015 16:24
MySQL Table Size
SELECT (data_length+index_length)/power(1024,3) tablesize_mb
FROM information_schema.tables
WHERE table_schema='ProposalAgent' and table_name='proposals';
@jheth
jheth / movies.txt
Created November 3, 2015 02:50
Movies
A Perfect Man
Best of Me - Good
Begin Again - Recommend
Celeste and Jesse Forever - Good
a case of you
@jheth
jheth / run_mutant.rb
Created November 9, 2015 02:11
mutant command line
bundle exec mutant --include lib/ --require dynamics_crm --fail-fast --use rspec DynamicsCRM::Client
# Turn off the automatic pager
Pry.config.pager = false
# Make the prompt silly.
Pry.config.prompt_name = 'oh no!'
# Hit Enter to repeat last command
#Pry::Commands.command(/^$/, 'repeat last command') do
# _pry_.run_command Pry.history.to_a.last
#end
@jheth
jheth / bulk_delete_redis.sh
Created November 29, 2016 19:16
Bulk Redis Delete
redis-cli KEYS "Proposal*" | xargs redis-cli DEL
# Default 1 MB
show variables like 'max_allowed_packet'
# 10 MB
set global max_allowed_packet=10485760
@jheth
jheth / go-clean-string.go
Last active January 3, 2018 17:58
GoLang CleanString
// Hacky way to strip unicode characters.
func CleanText(text string, maxLength int) string {
if len(text) < 5 {
return ""
}
if strings.Contains(text, "\n") {
sections := strings.Split(text, "\n")
newText := sections[0]
for idx, s := range sections {
@jheth
jheth / update-from-sub-query.sql
Last active January 24, 2018 16:00
sql update from sub-query
-- great way to batch update using a sub-query in the from clause
update category set catid=100
from (
select event.catid
from event
left join category cat on event.catid = cat.catid
where cat.catid is null
limit 1000
) eventcat
where category.catid = eventcat.catid
@jheth
jheth / MarshalJSON.go
Created March 22, 2018 13:37
NullInt64 MarshalJSON
// NullInt64 is an alias for sql.NullInt64 data type
type NullInt64 sql.NullInt64
// MarshalJSON for NullInt64
func (ni *NullInt64) MarshalJSON() ([]byte, error) {
if !ni.Valid {
return []byte("null"), nil
}
return json.Marshal(ni.Int64)
^[^iIoOqQ'-]{10,17}$