Skip to content

Instantly share code, notes, and snippets.

View btedev's full-sized avatar

Barry Ezell btedev

  • St. Petersburg, FL
View GitHub Profile
@btedev
btedev / app.js
Created December 11, 2023 19:54 — forked from cblavier/app.js
Responsive Phoenix LiveView
const Hooks = { ViewportResizeHooks}
const connectLiveSocket = () => {
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute('content')
const liveSocket = new LiveSocket('/my_app/live', Socket, {
params: {
_csrf_token: csrfToken,
viewport: {
width: window.innerWidth,
height: window.innerHeight
@btedev
btedev / vimrc
Created July 10, 2013 13:52
My vimrc
"Turn off any hacks vim does to be vi backwards-compatible
set nocompatible
"Set Mapleader
let mapleader = ","
let g:mapleader = ","
"Use pathogen to manage plugin bundles
"See http://www.vim.org/scripts/script.php?script_id=2332
filetype off
@btedev
btedev / gist:4157285
Created November 27, 2012 21:43
MySQL temp table example for missing values
create table pantry(name varchar(50), quantity int);
insert into pantry values('soup', 10), ('celery', 5), ('crackers', 2);
create temporary table shopping_list(name varchar(50));
insert into shopping_list values ('soup'), ('onion'), ('celery');
select a.name, ifnull(b.quantity, 0) as quantity
from shopping_list a
@btedev
btedev / gist:3528703
Created August 30, 2012 13:38
Untar multiple files with one command
ls *.tar | xargs -i tar xf {}
# Hash keyed by y to speed to_s
def to_h
hash_with_default = Hash.new {|hash,key| hash[key] = []}
@points.inject(hash_with_default) { |hash, point| h[point.y] << point.x; hash }
end
@btedev
btedev / tmux_install_ubuntu.txt
Created March 28, 2012 21:53
Installing tmux on Ubuntu server 10.04
1. Install lib event from source http://libevent.org/
2. Install tmux from source with:
.configure LDFLAGS="-L/usr/local/lib"
@btedev
btedev / table_sizes.sql
Created March 20, 2012 20:59
Get table sizes in MySQL
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "my_database_name";
# One-liner based on an image a friend sent in an email...
(1..9).inject("") { |s,i| s+=i.to_s; puts "#{s.to_i}*8+#{i} = #{s.to_i*8+i}".center(25); s }
@btedev
btedev / disable_mysql_bin_log.txt
Created February 19, 2012 17:59
Disable the MySQL binary log while restoring data from mysqldump
# Disable the MySQL binary log while restoring data from mysqldump
(echo "set session sql_log_bin=0;"; cat some_dump.sql) | mysql ...
@btedev
btedev / copy_files_efficiently.txt
Created February 15, 2012 14:24
Efficient file copying using pigz and nc
From Tumblr slidedeck "Massively Sharded MySQL" (http://assets.en.oreilly.com/1/event/74/Massively%20Sharded%20MySQL%20at%20Tumblr%20Presentation.pdf):
Our shard-split process relies on creating new slaves quickly, which involves copying around very large data sets.
For compression we use pigz (parallel gzip), but there are other alternatives.
On destination box:
$ nc -l [port] | pigz -d | tar xvf -