Skip to content

Instantly share code, notes, and snippets.

View X0nic's full-sized avatar

Nathan Lee X0nic

View GitHub Profile
@X0nic
X0nic / list-memcache-keys.rb
Created November 19, 2013 19:36
List local memcache keys in ruby
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Copied from: https://gist.github.com/bkimble/1365005
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
@X0nic
X0nic / renamer.rb
Last active January 2, 2016 06:09
Rename mp3s based on tags
#!/usr/bin/env ruby
# Thanks to: Ahmad Azizan
# http://blog.lab69.com/2012/02/renaming-mp3-files-with-ruby.html
# You need to require this..
require 'rubygems'
require 'mp3info'
# This variable will hold your first argument as directory
@X0nic
X0nic / gist:8659912
Created January 28, 2014 00:02
nginx maintance
set $is_trusted_ip false;
if ($http_x_forwarded_for ~ "68\.148\.96\.174") {
set $is_trusted_ip true;
}
@X0nic
X0nic / Vagrantfile
Last active August 29, 2015 13:59
Clean up chef server on vagrant destroy
# Borrowed from https://coderwall.com/p/sikrdw
module Vagrant
module Provisioners
class Base
require 'chef'
require 'chef/config'
require 'chef/knife'
end
@X0nic
X0nic / Vagrantfile
Created July 3, 2014 22:36
Vagrantfile loading run_list via json
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'multi_json'
Vagrant::Config.run do |config|
# Will load nodes/vagrant.json
VAGRANT_JSON = MultiJson.load(Pathname(__FILE__).dirname.join('nodes', 'vagrant.json').read)
@X0nic
X0nic / advcomp.rb
Created July 23, 2014 20:28
advcomp Homebrew Formula (advpng and advdef)
require 'formula'
class Advcomp < Formula
homepage 'http://advancemame.sourceforge.net/'
url 'http://downloads.sourceforge.net/project/advancemame/advancecomp/1.19/advancecomp-1.19.tar.gz'
sha256 'd594c50c3da356aa961f75b00e958a4ed1e142c6530b42926092e46419af3047'
def install
system "./configure"
system "make install"
@X0nic
X0nic / chruby_ruby-build.sh
Created June 19, 2016 05:09 — forked from havenwood/chruby_ruby-build.sh
On Debian, Ubuntu, or Mint: install Ruby with chruby and ruby-build
# Install apt-get packages:
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
# Install chruby:
cd
wget https://github.com/downloads/postmodern/chruby/chruby-0.2.3.tar.gz
tar -xzvf chruby-0.2.3.tar.gz
cd chruby-0.2.3
sudo make install
@X0nic
X0nic / hab.sh
Created July 5, 2016 05:04
Install Habitat
wget -O hab.tar.gz 'https://api.bintray.com/content/habitat/stable/linux/x86_64/hab-$latest-x86_64-linux.tar.gz?bt_package=hab-x86_64-linux'
tar xf hab.tar.gz
cd hab-0.7.0-20160614230104-x86_64-linux/
sudo ./hab install core/hab
sudo ./hab pkg binlink core/hab hab
sudo useradd hab -u 42 -g 42 -d / -s /bin/sh -r
sudo groupadd -og 42 hab
@X0nic
X0nic / step1.sh
Last active August 2, 2024 09:55
Habitat Rails Sample Comands
# hab studio enter
hab pkg export docker core/postgresql
hab pkg export docker core/ruby-rails-sample
# Terminal - 1
docker run -e HAB_POSTGRESQL='initdb_superuser_password = "rails_sample"' -p 9631:9631 -p 5432:5432 -v rails_pg_data:/hab/svc/postgresql/data -it core/postgresql
# Terminal - 2
@X0nic
X0nic / convert-csv-to-json.rb
Created August 29, 2016 16:52
Convert a csv to json
#! /usr/bin/env ruby
require 'csv'
require 'json'
csv = CSV.parse(File.read(file_name).scrub, headers: true)
hash = csv.map{ |row| { code: row["Classification Code"], description: row["Classification Code Description English"] } }
json = hash.to_json