Skip to content

Instantly share code, notes, and snippets.

@mahemoff
mahemoff / destroy-all-elasticsearch-indexes.md
Created May 18, 2017 04:30
How to destroy all ElasticSearch indexes on Homebrew

Sometimes it gets into inconsistent state. For testing purposes, we don't want to debug it, we just want to start again.

  1. kill elasticsearch if it's running
  2. brew info elasticsearch
  3. Look for a line like `Data: /usr/local/var/elasticsearch/elasticsearch_foo/
  4. rm -fr /usr/local/var/elasticsearch/elasticsearch_foo
  5. restart elasticsearch and enjoy your tabula rasa
@mahemoff
mahemoff / rails-blank-fixtures.md
Created May 16, 2017 09:45
Rails needs blank fixtures

Something I noticed after settiing use_transactional_tests = false is that fixture files need to be present even if they don't have any data. An empty yml file means the model will be reset after every test run, i.e. you won't have side effects from creating new instances in a test.

It feels off to see an empty file (or just commented) and keep it in the project, but you need to do it.

@mahemoff
mahemoff / README-TOO.md
Created May 13, 2017 07:01
Octopus setup

Expanding on the README...

(Work in progress, read at own risk as some info may be wrong)

Set "main" database

This is the initial database Rails uses. If there's a core database in the system, specify this one.

In config/database.yml (not shards.yml). Simple version:

@mahemoff
mahemoff / README.md
Last active January 6, 2023 15:56
MySQL thread-safe multi-database switching in Rails 5

The code here is a tech demo showing how to switch between databases in Rails 5, in a thread-safe manner.

BACKGROUND: HOW NOT TO CHANGE DATABASES

The simple way to switch databases is:

ActiveRecord::Base.establish_connection :user_shard1
puts User.find(1) # this is executed on the database keyed on "user_shard1" in database.yml
ActiveRecord::Base.establish_connection :development
@mahemoff
mahemoff / domain-sale.md
Created April 6, 2017 11:28
Selling a domain: some advice

I used Escrow.com successfully to sell a domain, but I did learn later there's a potential fraud as they only take control of the buyer's funds, not the seller's domain. The domain is still transferred directly from seller to buyer. There's potential fraud where the seller hides the domain after you xfer it, and tries to get their money back from the escrow.

Not sure how much of an issue in practice, it partly will depend on your confidence in the buyer (escrow actually told me they know the buyer well so I was fairly confident). Ideally you should find a good escrow that takes both sides before swapping them, but not sure if there are any trusted names that do this tbh.

@mahemoff
mahemoff / xtradb-ubuntu.md
Created March 30, 2017 15:03
Issues installing Percona Xtradb

First, DNS problems - Linode pointed me to https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/1674532 (mainly need to up sudo apt-get update && sudo apt-get upgrade, possibly reboot)

As quick fix, appended dns-nameservers 8.8.8.8 8.8.8.9 to /etc/network/interfaces and running "sudo service networking restart".

vi /etc/apt/sources.list Append:

deb http://repo.percona.com/apt xenial main testing
deb-src http://repo.percona.com/apt xenial main testing
@mahemoff
mahemoff / describe-mysql-5.7.17-user-table
Created February 2, 2017 09:51
maria 10 to mysql 5.7 (due to fork, they have different user tables)
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y')
@mahemoff
mahemoff / mysql.sh
Last active October 6, 2019 01:26
circleci mysql upgrade
#!/bin/bash
set -x
set -e
export DEBIAN_FRONTEND=noninteractive
sudo apt-get --purge autoremove -y mysql-server-5.6
curl -LO https://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
echo mysql-apt-config mysql-apt-config/select-product select Apply | sudo debconf-set-selections
@mahemoff
mahemoff / private.xml
Created January 17, 2017 09:23
Karabiner tmux - make caps lock main tmux key and backquote secondary tmux key for shell sessions
<?xml version="1.0"?>
<root>
<appdef>
<appname>Terminal</appname>
<equal>com.apple.Terminal</equal>
<equal>iTerm</equal>
<equal>net.sourceforge.iTerm</equal>
<equal>com.googlecode.iterm2</equal>
</appdef>
<item>
fm.player.playback.play // play/resume
fm.player.playback.pause // pause
fm.player.playback.jumpforward // jump forward
fm.player.playback.jumpback // jump back
fm.player.playback.next // skip to next episode
fm.player.playback.previous // skip back to previous episode
fm.player.playback.stop // stop
fm.player.playback.toggle // toggle play/pause state