Skip to content

Instantly share code, notes, and snippets.

@mrkplt
mrkplt / gist:c6fb95cb613fed2075bc
Created July 10, 2014 14:44
Turn in a string into a valid local variable name.
def variablize(string)
sanitized_string = string.chomp('=')
sanitized_string = sanitized_string.gsub(/([^a-z0-9_])/i, '_')
sanitized_string[0] = sanitized_string[0].downcase.sub(/[0-9]/, '_')
sanitized_string
end
# extracted from http://www.thekua.com/atwork/2011/07/ruby-script-to-capture-http-traffic/
require 'webrick'
include WEBrick
class Simple < WEBrick::HTTPServlet::AbstractServlet
def do_POST(request, response)
puts "Body: " + request.body
puts "Header: " + request.raw_header.to_s
@mrkplt
mrkplt / potty_mouth.rb
Last active August 29, 2015 14:00
You've got a potty mouth
require 'csv_class_maker'
CsvClassMaker.generate_class('MyTweets', '/Users/mplatt/Downloads/tweets/tweets.csv')
curses = Regexp.new('piss|fuck|shit|dick|ass|damn', true)
all_tweets_count = MyTweets.all.size
my_curses_count = MyTweets.all.select{ |t| t if t.text.match(curses) }.size
{
"auto_indent": true,
"bold_folder_labels": true,
"detect_indentation": true,
"fade_fold_buttons": false,
"font_face": "Fira Mono OT",
"font_size": 13.0,
"highlight_line": true,
"ignored_packages":
[
# http://michaelconnor.org/2013/07/install-mongodb-on-amazon-64-bit-linux/
sudo vi /etc/yum.repos.d/10gen.repo
# Add all below sans pounds to the file
# [10gen]
# name=10gen Repository
# baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
# gpgcheck=0
@mrkplt
mrkplt / gist:8340878
Last active January 2, 2016 17:59
Getting postgres, unicorn and nginx running on an e2 instance. There are config files to accompany this. Will link later.
# http://codingsteps.com/installing-and-configuring-postgresql-in-amazon-linux-ami/
sudo su -
gem install unicorn
exit
sudo yum -y install nginx
sudo yum -y install readline-devel
sudo yum -y install zlib-devel
wget http://ftp.postgresql.org/pub/source/v9.2.6/postgresql-9.2.6.tar.bz2
@mrkplt
mrkplt / ruby_2_install_at_amazon.rb
Last active January 2, 2016 01:19
Pulls ruby 1.8.7 out of the amazon instance. Installs 2.0.
#!/bin/bash
# I don't know if this will actually run as a script, but I threw the shebang in anyway
# executing the individual step works fine.
###############################################
# To use:
# wget -O install-ruby-2.sh https://gist.github.com/mrkplt/8229498/raw
# chmod 755 install-ruby-2.sh
# sudo ./install-ruby-2.sh
###############################################
sudo yum -y update
@mrkplt
mrkplt / redis-server
Last active January 1, 2016 11:19 — forked from tessro/redis-server
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
#!/bin/bash
###############################################
# To use:
# wget -O install-redis.sh https://gist.github.com/mrkplt/8137324/raw
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
echo "*****************************************"
@mrkplt
mrkplt / threads_and_signals.rb
Last active December 31, 2015 13:39
Same as https://gist.github.com/mrkplt/7993228 except it spins up threads to do things in.
@hello = 'Hello'
puts Process.pid
thread_array = Array.new
thread_array << Thread.new do
Signal.trap('USR1'){
@hello = 'HALLO!'
}
Signal.trap('USR2'){