Skip to content

Instantly share code, notes, and snippets.

View dinedal's full-sized avatar
👾

Paul Bergeron dinedal

👾
View GitHub Profile
def upload_sizing
result = {}
size = {:width => self.upload_width, :height => self.upload_height}
thumb_size = {:width => self.upload_thumb_width, :height => self.upload_thumb_height}
keys = []
keys.push "resize" if self.enable_images?
keys.push "encode" if self.enable_videos?
keys.each do |key|
#!/usr/bin/env ruby
queue_length = `/opt/redis-2.2.2/bin/redis-cli zcard q:jobs:total_report:inactive`
begin
if queue_length.to_i > 50000
puts "status ok there are #{queue_length.to_i} jobs"
elsif queue_length > 10000
puts "status warn there are #{queue_length.to_i} jobs"
else
puts "status err there are #{queue_length.to_i} jobs"
@dinedal
dinedal / send_request.coffee
Created November 7, 2011 22:17
Sample code to send request to Chronicle
http = require 'http'
util= require 'util'
options = {
host: 'api.staging.cloud.vitrue.com',
port: 80,
path: '/chronicle/1/',
method: 'GET',
disable_ssl_peer_verification: true,
timeout: 200
class Integer
def factorial_iterative
f = 1; for i in 1..self; f *= i; end; f
end
def sum_digits
self.to_s.split(//).collect { |d| d.to_i}.sum
end
end
# coffeescript, deps include node ~v0.6.6, jsdom, jQuery (node version)
fs = require 'fs'
jsdom = require 'jsdom'
data = []
deviation = []
sum = 0
devnsum = 0
def zipflaw(x, i)
j = 0
k = 1
i.times do
# I was stuck for awhile because I wasn't using floating points and the error was enough to move my answer back by 2 ranks!
j += x.to_f/k.to_f
k += 1
end
j
end
@dinedal
dinedal / chronicle.rake
Created February 17, 2012 19:33
Chronicle Migration Script
namespace :chronicle do
desc "Rename Store tags in Chronicle after Accounts integration"
task :migrate_for_accounts, [:client_id] => :environment do |t, args|
client = Client.find(args.client_id)
vitrue_id = client.vitrue_id_for_account.to_s
stores = client.stores
stores.find_each do |store|
old_tag = "s:#{store.id}"
new_tag = "s:#{store.vitrue_id_for_resource}"
# ChronicleClient::Tabs::TagRename.rename(old_tag, new_tag, vitrue_id)
[1] pry(main)> class Foo
[1] pry(main)* class Bar
[1] pry(main)* end
[1] pry(main)* end
nil
[2] pry(main)> foo = Foo.new
#<Foo:0x007f8cea8121e8>
[3] pry(main)> Foo::Bar
Foo::Bar < Object
# Simple examples are wussy, here's a complicated one
# User belongs_to Circle, Tags has_many User, Tags has_many Circle
Factory :user do
has_a :circle
has_many :tag
end
Factory :circle do
@dinedal
dinedal / emacs.rb
Last active December 11, 2015 05:38
emacs 24 latest fullscreen patch
require 'formula'
class Emacs < Formula
homepage 'http://www.gnu.org/software/emacs/'
url 'http://ftpmirror.gnu.org/emacs/emacs-24.2.tar.bz2'
mirror 'http://ftp.gnu.org/pub/gnu/emacs/emacs-24.2.tar.bz2'
sha1 '38e8fbc9573b70a123358b155cf55c274b5a56cf'
option "cocoa", "Build a Cocoa version of emacs"
option "srgb", "Enable sRGB colors in the Cocoa version of emacs"