Skip to content

Instantly share code, notes, and snippets.

View ymek's full-sized avatar

Myke Ahn-Stubbs ymek

  • cyberspace
View GitHub Profile
@ymek
ymek / ramlgen.sh
Created August 2, 2016 17:18
Generate HTML/Markdown from RAML on file changes
#!/usr/bin/env bash
#
# Attempts to regenerate HTML and Markdown files from RAML upon component
# file changes.
#
# NOTE: Requires `fswatch`
FSWATCH=$(which fswatch)
RAML2HTML=$(which raml2html)
RAML2MD=$(which raml2md)
#
# Many novices, looking to get started with web programming, fall into the trap
# of learning Rails before achieving a solid grasp of the Ruby language. To
# understand Rails, one should have a basic understanding of programming
# fundamentals, especially Objects and Inheritance.
#
# Additionally, there are many Rails-specific methods patched into the Object
# class. While this is incredibly convenient, it makes learning Ruby as
# a language somewhat obtuse. For an example, consider the following snippet:
foo = []
@ymek
ymek / mount_s3_as_filesystem.sh
Created September 22, 2015 22:14
Mount s3 as a filesystem on Amazon Linux
# NOTE: the majority of these commands should be run as root
# install dependency packages
yum install -y gcc libstdc++-devel gcc-c++ fuse fuse-devel curl-devel libxml2-devel openssl-devel mailcap autoconf automake
mkdir -p $HOME/src
cd $HOME/src
# download/extract the latest source tarball
wget https://github.com/s3fs-fuse/s3fs-fuse/archive/master.tar.gz
@ymek
ymek / new_origin.sh
Last active August 29, 2015 14:21
Migrate Git Repo's Remote Origin And Set Tracking Branches
NEW_REMOTE="git@github.com:your/repo.git"
# Rename the old origin
# Add the new origin
# Push all local branches to new origin and set respective tracking branches
git remote rename origin old_origin
git remote add origin $NEW_REMOTE
git remote push --all -u origin
# NOTE: Could benefit from refactor to use a "git clone --mirror" flow
# Generated by iptables-save v1.4.21 on Fri Mar 6 01:19:41 2015
*filter
:INPUT ACCEPT [5321:859636]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4300:2722225]
:LOGDROP - [0:0]
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 --name DEFAULT --mask 255.255.255.255 --rsource -j LOGDROP
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name DEFAULT --mask 255.255.255.255 --rsource
-A LOGDROP -j LOG
-A LOGDROP -j DROP
def cache_key_for_foo
cache_key_prefix_from_method
end
def cache_key_prefix_from_method
calling_method = ::Kernel.caller[0][/`.*'/][1..-2]
calling_method[14..-1] # length of "cache_key_for_"
end
@ymek
ymek / app.models.concerns.collection.rb
Last active August 29, 2015 14:04
Cache Keys for ActiveRecord Associations
module Collection
extend ActiveSupport::Concern
included do
def cache_key(updated_at_field = :updated_at)
class_name = self.class.to_s.demodulize.downcase
count = self.count
max_updated_at = self.maximum(updated_at_field).try(:utc).try(:to_s, :number)
"#{class_name}/#{count}/#{max_updated_at}"
end
#!/usr/bin/env ruby
def traverse_and_rename(dir)
Dir.entries(dir).each do |entry|
next if %w(. ..).include?(entry) || !File.directory?(entry)
if entry[/[A-Z]/]
File.rename(entry, entry.downcase)
else
Dir.chdir(entry) do
STDOUT.sync
def build_spinner
chars = %w(🙉 🙉 🙈 🙈 🙊 🙊 🙈 🙈).cycle
Thread.new do
loop do
print chars.next + ' '
sleep(0.1)
print "\b\b\b"
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Example for batch CSV updates
Convert a given CSV file to a JSON object
"""
import sys
import csv