Skip to content

Instantly share code, notes, and snippets.

View unixmonkey's full-sized avatar

David Jones unixmonkey

View GitHub Profile
@stevez
stevez / gist:3946134
Created October 24, 2012 13:45
gzip_ruby
require 'zlib'
require 'stringio'
require 'json'
def gunzip(data)
io = StringIO.new(data, "rb")
gz = Zlib::GzipReader.new(io)
decompressed = gz.read
end
@thegrubbsian
thegrubbsian / current_timezone.js
Created September 30, 2012 21:45
Get the Current Timezone Offset in Hours in JavaScript, adjusting for Daylight Savings Time
function currentTimezoneOffset() {
var dstPeriod = {
2012: [new Date(2012, 2, 11), new Date(2012, 10, 4)],
2013: [new Date(2013, 2, 10), new Date(2013, 10, 3)],
2014: [new Date(2014, 2, 9), new Date(2014, 10, 2)],
2015: [new Date(2015, 2, 8), new Date(2015, 10, 1)],
2016: [new Date(2016, 2, 13), new Date(2016, 10, 6)],
2017: [new Date(2017, 2, 12), new Date(2017, 10, 5)],
2018: [new Date(2018, 2, 11), new Date(2018, 10, 4)],
2019: [new Date(2019, 2, 10), new Date(2019, 10, 3)],
@kuleszaj
kuleszaj / bootstrap.sh
Created July 8, 2012 19:16
Puppet Bootstrap, Ubuntu
#!/bin/bash
# Update our package manager...
sudo apt-get update
# Install dependencies for RVM and Ruby...
sudo apt-get install -y build-essential libxslt1-dev libxml2-dev libreadline-dev zlib1g-dev libssl-dev curl git-core
# Get and install RVM
curl -L https://get.rvm.io | sudo bash -s stable
@kuleszaj
kuleszaj / deploy.rb
Created July 8, 2012 19:15
Capistrano Configuration to Run Puppet
require "rvm/capistrano"
...
namespace :bootstrap do
task :default do
# Specific RVM string for managing Puppet; may or may not match the RVM string for the application
set :user, "ubuntu"
# Set the default_shell to "bash" so that we don't use the RVM shell which isn't installed yet...
set :default_shell, "bash"
@tessro
tessro / kill-slow-queries.sh
Created June 6, 2012 18:51
A script for killing slow MySQL queries, suited for a cron job
#!/bin/sh
# Credentials for a MySQL user with PROCESS, SUPER permissions
USERNAME=
PASSWORD=
# MySQL Server location
HOST=127.0.0.1
PORT=3306
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
#!/usr/bin/env ruby
CHARACTERS = (('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a)
GROUP = 53
MY_MACHINE_DYNDNS_ADDRESS = "Put your DynDns DNS name here"
MY_SSH_PORT = "Your router's external port that will forward to SSH" # as a Fixnum
def ridiculous_password
(1..20).map do
@RiANOl
RiANOl / gist:1077760
Last active April 13, 2024 06:17
AES128 / AES256 CBC with PKCS7Padding in Ruby
require "openssl"
require "digest"
def aes128_cbc_encrypt(key, data, iv)
key = Digest::MD5.digest(key) if(key.kind_of?(String) && 16 != key.bytesize)
iv = Digest::MD5.digest(iv) if(iv.kind_of?(String) && 16 != iv.bytesize)
aes = OpenSSL::Cipher.new('AES-128-CBC')
aes.encrypt
aes.key = key
aes.iv = iv
@brianmario
brianmario / config.ru.rb
Created April 21, 2011 06:11
minimal rails3 app
# minimal rails3 app
require 'action_controller'
Router = ActionDispatch::Routing::RouteSet.new
Router.draw do
root :to => 'site#index'
end
class SiteController < ActionController::Metal
This is a brief description of how to get VestalVersions and Paperclip to play nicely.
The paperclip_initializer.rb extends paperclip for a new option :keep_old_files which means that paperclip won't remove the file when a new file is uploaded. In order for this to work, the model also needs to have to have specific settings:
#1. The version needs to be included in the file path
#2. A method to get the actual path to the file. (The file may not be at the current version)
You can view both these settings in the model_files.rb file below.
Note: If you dealing with public files then you will need to include the :id_and_version option in the :url and :path. Then in the view you need to reference the model_file.versioned_file_path.