Skip to content

Instantly share code, notes, and snippets.

@tamoyal
tamoyal / gist:a2fd3d76f6327d8e963f5136291c073d
Created September 17, 2021 23:52
For batch converting aif to mp3 and keeping original filename
for f in *.aif;
do
ffmpeg -i "$f" -f mp3 -acodec libmp3lame -ab 192000 -ar 44100 "${f%.aif}".mp3;
done
@tamoyal
tamoyal / main.dart
Created May 30, 2020 22:17
Audio Chat Bubble with Clip (not working)
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@tamoyal
tamoyal / main.dart
Created May 30, 2020 22:07
Audio chat bubble
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@tamoyal
tamoyal / sync_me
Created September 30, 2015 00:46
Script to sync a local directory to external hard drive
#!/usr/bin/env bash
# This will sync LOCAL_DIR directory to XTAL_DIR (which is my xtal hard drive)
# It's meant to run on frequent polling cron job so that it syncs "immediately"
# when the xtal is plugged in. It will do nothing if the xtal drive is not
# plugged in.
# After a successful sync, it will change the crontab so it is not sync'd again
# for 24 hours. This script assumes you don't need more frequent backing up than
# that because I use it for my projects directory where everything important is
@tamoyal
tamoyal / gist:1b7ec4d3871b343d353d
Last active January 15, 2023 22:06
Transitioning your pem/key on an EC2 instance

Note: This is mainly useful for instances you are essentially locked out of in the case where you don't want to create a new instance.

  1. Launch a micro instance with your new key (we'll call this the "key transitioning instance"). This instance will need to be in the same availability zone ("us-east-1b", for example) as the instances you are locked out of.
  2. Make sure you can ssh in
  3. Select the instance you are locked out of and make note of the attached EBS volume ID which will look something like vol-6a844e25 and the Root Device which will look something like /dev/sda1.
  4. Stop the EC2 instance you are locked out of
  5. Go to that instance's Root Device EBS volume and detach it
  6. Re-attach the EBS volume to the key transitioning instance
  7. On the key transitioning instance, run sudo fdisk -l
  8. Note the "Device" column output from this command that is similar to the "Attachment information" which is displayed when you select the EBS volume (we'll use /dev/xvdf1 as an example). That will be yo
@tamoyal
tamoyal / gist:38287887923cc29869e5
Created December 29, 2014 20:02
Upgrade Postgres 9.3 to 9.4 on OS X
# Shutdown postgres
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
# Install 9.4
brew update && brew upgrade postgresql
# Make 9.4 DB
initdb /usr/local/var/postgres9.4 -E utf8
# Upgrade postgis or the upgrade will fail (if you require postgis)
@tamoyal
tamoyal / gist:2ea1fcdf99c819b4e07d
Last active February 13, 2020 11:24
Upgrade Postgres 9.3 to 9.4 on Ubuntu
# Be sure to save your config files. Optional but I do:
sudo cp /etc/postgresql/9.3/main/postgresql.conf ~
sudo cp /etc/postgresql/9.3/main/pg_hba.conf ~
# Package repo (for apt-get)
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
# Also probably optional but I like to update sources and upgrade
sudo apt-get update
@tamoyal
tamoyal / gist:33df0699327e503d3cf9
Created October 19, 2014 23:00
Some Resque helpers
# There are Minitest tests for reliably_enqueue below the module
# Note that this isn't well tested because it was used briefly for maintenance and we ended up killing Resque
# I apologize in advance for any off-by-one errors
module Resque
SLEEP_BETWEEN_RETRY = 0.1.freeze
RETRY = 3
NUM_PROCS_FOR_FAST_ENQUEUE = 10
class << self
@tamoyal
tamoyal / gist:10441108
Created April 11, 2014 04:39
Create super user and database user in Mongo 2.6
# Create your superuser
$ mongo
> use admin
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]})
> exit
# Alias for convenience (optional and at your own risk)
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile
$ source ~/.bash_profile
@tamoyal
tamoyal / gist:10303138
Last active August 29, 2015 13:58
Update Postgres 9.1 to 9.3 on Ubuntu
# Note this uses a dump and restore method. You can try using pg_upgrade instead
# Make a copy of postgresql.conf and hba.conf since you'll want to use those to edit the 9.3 conf later
$ sudo cp /etc/postgresql/9.1/main/postgresql.conf ~
$ sudo cp /etc/postgresql/9.1/main/pg_hba.conf ~
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
$ sudo apt-get update
$ sudo apt-get upgrade