Skip to content

Instantly share code, notes, and snippets.

View damien's full-sized avatar
🤝
Open for business! Hire me for your project at https://mindglob.com

Damien Wilson damien

🤝
Open for business! Hire me for your project at https://mindglob.com
View GitHub Profile
vagrant@salt-master:~$ ps -efl|egrep salt-master
1 S root 6247 1 0 80 0 - 114799 poll_s 18:16 ? 00:00:00 /usr/bin/python /usr/bin/salt-master
1 S root 6249 1 0 80 0 - 114181 poll_s 18:16 ? 00:00:00 /usr/bin/python /usr/bin/salt-master
1 S root 6250 1 0 80 0 - 114181 poll_s 18:16 ? 00:00:00 /usr/bin/python /usr/bin/salt-master
1 S root 6253 1 0 80 0 - 114179 poll_s 18:16 ? 00:00:00 /usr/bin/python /usr/bin/salt-master
4 S root 6300 1 0 80 0 - 127915 poll_s 18:16 ? 00:00:00 /usr/bin/python /usr/bin/salt-master
1 S root 6311 6300 0 80 0 - 71406 pipe_w 18:16 ? 00:00:00 /usr/bin/python /usr/bin/salt-master
1 S root 6318 6300 0 80 0 - 62379 poll_s 18:16 ? 00:00:00 /usr/bin/python /usr/bin/salt-master
1 S root 6319 6300 0 80 0 - 62379 poll_s 18:16 ? 00:00:00 /usr/bin/python /usr/bin/salt-master
1 S root 6326 6300 0 80 0 - 191654 poll_s 18:16 ? 00:00:00 /usr
class SearchController < ApplicationController
def index
if search_params.blank? && where_params.blank?
@portfolios = Portfolio
.includes([:user, :portrait])
.where(published: true)
.order('created_at DESC')
else
@portfolios = search_portfolio search_params, where_params
@damien
damien / course_code.rb
Created December 18, 2014 17:20
Course code parser
# A parser for course code strings
#
# Course codes are unique identifiers used to identify particular classes instructed at an edicuational institution.
#
# There isn't any real standard for course codes, but the examples below demonstrate common formats for course codes
# in the places where this parser is used.
#
# The parser itself is generated using [Treetop](https://github.com/nathansobo/treetop), so look there if you're interested
# in the underlying framework that generates the CourseCodeParser class when we load up our parser grammar.
#
@damien
damien / as_logger.rb
Created January 23, 2015 23:10
Nicely formatted logger
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = -> (severity, datetime, progname, msg) { format('[%-5.5{severity} %{timestamp}] %{msg}', severity: severity, timestamp: datetime.to_s(:db), msg: msg) + "\n" }
logger.unknown 'foo'
logger.fatal 'bar'
logger.error 'fizz'
logger.warn 'buzz'
logger.info 'alice'
logger.debug 'bob'
@damien
damien / prime.rb
Created April 14, 2015 15:20
Lazily generate primes in ruby
# Functional implementation of the Sieve of Eratosthenes
#
# Once initialized, an instance of this class may be used to generate an
# infinite number of primes.
#
# @see https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
# @see http://raganwald.com/2013/02/23/sieve.html
#
# Example:
# @sieve = EratosthenesIncrementalSieve.new
@damien
damien / recurse.rb
Last active August 29, 2015 14:23
Utilities for performing recursive operations on an object
module Recurse
# Iterate over obj and all of it's values, copying them into a flat array
# @return [Array]
# @example Flattening a nested hash
# { foo: { bar: { fizz: 'buzz' } } }.flatten_recursively
# # => [:foo, :bar, :fizz, "buzz"]
#
# @example Flattening an array of mixed objects
# [{ fizz: :buzz }, { foo: :bar }, [1, [2, 3]]].flatten_recursively
# # => [:fizz, :buzz, :foo, :bar, 1, 2, 3]
@damien
damien / backup.rake
Created January 11, 2009 02:18
Collection of useful rake tasks for rails applications.
require 'find'
namespace :db do
desc "Backup the database to a file. Options: DIR=base_dir RAILS_ENV=production MAX=20"
task :backup => [:environment] do
datestamp = Time.now.strftime("%Y-%m-%d_%H-%M-%S")
base_path = ENV["DIR"] || "db"
backup_base = File.join(base_path, 'backup')
backup_folder = File.join(backup_base, datestamp)
backup_file = File.join(backup_folder, "#{RAILS_ENV}_dump.sql.gz")
#! /bin/bash
##
# .bash_extras
#
# bash profile customizations. Just source this file to get things rolling!
##
# [damien@Protos:/etc] 21:00:20 $
export PS1='[\[\033[36m\]\u@\h\[\033[31m\]:\[\033[33m\]\w\[\033[0m\]] \[\033[35m\]\D{%H:%M:%S}\[\033[0m\] \$ '