Skip to content

Instantly share code, notes, and snippets.

View JadedEvan's full-sized avatar

Evan Reeves JadedEvan

View GitHub Profile
@JadedEvan
JadedEvan / s3cmd bucket to bucket copy
Created March 29, 2010 22:37
Copy files from one S3 bucket to another
#!usr/bin/env ruby
# This script takes a list of filenames from a given file and copies
# each of those files from one S3 bucket to another using the s3mcd library.
# Inputfile should have each filename termination by a newline character.
file, from, to = ARGV[0], ARGV[1], ARGV[2]
if file.nil? || from.nil? || to.nil?
puts "Invalid arguements. Should be filename from-s3-bucket to-s3-bucket"
@JadedEvan
JadedEvan / Ruby resized square thumbnails
Created April 20, 2010 18:01
Snippet of code that uses imagemagick to create a resized, square and centered thumbnail
`convert -resize x#{thisSize.to_i*2} -resize 50% -gravity center -crop #{thisSize}x#{thisSize}+0+0 +repage #{amazon_file[:tempfile].path} #{tempfile_new.path}`
@JadedEvan
JadedEvan / chars_remaining.js
Created June 21, 2010 18:05
Javascript onkeup() function that prevents entering more than X characters
function charsRemaining(evt, counterID, max) {
var chars = evt.getValue();
if (chars.length == 1 && chars[0] == '') { chars = []; }
var remaining = max - chars.length;
var counter = document.getElementById(counterID);
if (remaining >= 0) {
if(counter) counter.setTextValue(remaining + ' characters remaining');
}
else {
evt.setValue(evt.getValue().substr(0, max));
class Numeric
def ordinal
self.to_s + ( (10...20).include?(self) ? 'th' : %w{ th st nd rd th th th th th th }[self % 10] )
end
end
@JadedEvan
JadedEvan / vim-notes.mdown
Created September 22, 2011 18:24
Vim Tips - a catalog of useful Vim commands

Buffer Settings

:set scrolloffset=30
:set scrolloffset=999
:set so=0

Sets the offset when scrolling through a document. A value of 30 will keep a marginal amount of space while scrolling, a value of 999 will keep the cursor centered in the screen, a value of 0 restores Vim's default behavior. All of the above can be added to your ~/.vimrc file to set editor defaults. Vim wikia - scroll centering

Additional buffer settings

@JadedEvan
JadedEvan / unix-cli-tips.md
Last active December 12, 2019 06:41
UNIX Tips - a catalog of useful UNIX commands

find commands

find . -regextype posix-egrep -regex ".*(rb|js)$"

Find all files ending in .rb or .js.

find . -name "*js" -o -name "*rb"

Same as above, not using regular expressions.

@JadedEvan
JadedEvan / git-notes.mdown
Created July 25, 2012 17:23
Library of useful git commands

Git Notes

Merge Two Branches in seperate repos

I have two independent repositories (A and B) and would like to merge one repo. (B) into another one (A) with keeping the whole history of both. What do to?

% cd projectA
% git remote add test ../path/to/other/repo && git fetch test

Adds a new branch called test which pulls in ALL branches from the /other/repo. git fetch test pulls code for all branches

@JadedEvan
JadedEvan / HOWTO-openssl.md
Last active March 1, 2017 21:39
Various openssl commands

Self Signed Certificate

Generate a new RSA key of 4096 bits. Adding the -des3 (or any other cipher) requires that the key have a password issued:

openssl genrsa -out server.key 2048

Generate a new CSR (Certificate Signed Request)

openssl req -new -key server.key -out server.csr
@JadedEvan
JadedEvan / TUTORIAL-ruby-instance-methods-versus-attribute-accessors.md
Last active July 20, 2016 16:54
An article highlighting the difference in using instance methods over attribute accessors in Ruby classes. A fundamental concept that is often overlooked by beginner and intermediate Rubyists that can lead to cleaner, more predictable code

Ruby Design Patterns - Methods over Attributes

Overview

The objective of this article is to highlight the subtle differences between using class attributes and class methods in Ruby. Both offer a valid way to manipulate the state of an instance of a class. Things can get increasingly complex, hard to test and hard to maintain as more instance variables are introduced. Beginner and intermediate Rubyists often miss this subtle but important point which can introduce bugs that may be hard to fix in their native habitat.

The reasons I prefer to use methods over instance variables:

  • Increases predictability of method calls
  • Increases predictability when testing
@JadedEvan
JadedEvan / cloudformation-gnip-kinesis-connector.json
Created July 16, 2015 18:08
Amazon CloudFormation script to create a new EC2 server that runs the GNIP "sample-kinesis-connector" java application. This can be used to read incoming data from GNIP stream and push it over to Amazon Kinesis. GNIP pulled support for the Public AMI in the Amazon Marketplace, so here's one that will take you most of the way.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description": "Create EC2 instance to run a GNIP Kinesis connector. Creates CloudWatch alarms when 85% stream capacity reached.",
"Parameters" : {
"Environment" : {
"Type": "String",
"Description": "Environment in which to run",
"AllowedValues": ["production", "development"]
},
"InstanceTerminationProtection": {