Skip to content

Instantly share code, notes, and snippets.

View shadowbq's full-sized avatar
👔
Doing Things

shadowbq shadowbq

👔
Doing Things
View GitHub Profile
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@joshaven
joshaven / vash.rb
Created September 10, 2009 21:19
Volatile Ruby Hash > Vash
#############################################################################
# Class: Vash (Ruby Volatile Hash)
# Hash that returns values only for a short time. This is useful as a cache
# where I/O is involved. The primary goal of this object is to reduce I/O
# access and due to the nature of I/O being slower then memory, you should also
# see a gain in quicker response times.
#
# For example, if Person.first found the first person from the database & cache
# was an instance of Vash then the following would only contact the database for
# the first iteration:
@vast
vast / Rakefile
Created April 28, 2010 08:44
Interactive console for sinatra + activerecord
require 'my-sinatra-app'
require 'sinatra/activerecord/rake'
desc "run irb console"
task :console, :environment do |t, args|
ENV['RACK_ENV'] = args[:environment] || 'development'
exec "irb -r irb/completion -r my-sinatra-app"
end
@groesser3
groesser3 / lifo_fifo.rb
Created November 5, 2010 07:05
simple LIFO, FIFO functions in ruby
require "test/unit"
class Array
def fifo
verbrauch = inject(0) {|sum, el| sum+=el.abs if el < 0; sum }
res = select{|el| el > 0}.inject([]) do |result, el|
if el > verbrauch
result << (el - verbrauch)
verbrauch = 0
else
@denmarkin
denmarkin / mysql.god.rb
Created May 10, 2011 07:45
God recipes examples for Rackspace Cloud (Ubuntu) with resque and php-cgi. Try any of them with "sudo god -c /path/to/config -D"
God.watch do |w|
w.name = "mysqld"
w.interval = 30.seconds # default
w.start = "service mysql start"
w.stop = "service mysql stop"
w.restart = "service mysql restart"
w.start_grace = 20.seconds
w.restart_grace = 20.seconds
w.pid_file = "/var/lib/mysql/hostname.pid"
@morhekil
morhekil / LICENSE
Last active January 22, 2017 22:12
Implementation of deep symbolization of keys for Ruby hashes
The MIT License (MIT)
Copyright (c) 2015 Oleg Ivanov http://github.com/morhekil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@danielevans
danielevans / gist:1011309
Created June 6, 2011 23:01
A create admin rake task using the highline gem
namespace :admin do
desc "creates and admin user"
task :create => :environment do
line = HighLine.new # a command line lib that uses erb? Bizarre.
line.say "<%= color('Creating a new administrative user', BOLD) %>"
email = line.ask("Email: ")
pass = line.ask("Password: " ) { |q| q.echo = "*" }
admin = Admin.new(:email => email, :password => pass)
@btoone
btoone / curl.md
Last active April 2, 2024 20:18
A curl tutorial using GitHub's API

Introduction

An introduction to curl using GitHub's API.

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@cehoffman
cehoffman / .gitignore
Created April 27, 2012 18:50
Program to remove an IP Address from SSHGuard's blacklist
build/
@andsens
andsens / bootstrap_homeshick.sh
Last active December 27, 2023 12:47
Script that can set up an entire user account with homeshick automatically
#!/bin/bash -ex
# Paste this into ssh
# curl -sL https://gist.github.com/andsens/2913223/raw/bootstrap_homeshick.sh | tar -xzO | /bin/bash -ex
# When forking, you can get the URL from the raw (<>) button.
### Set some command variables depending on whether we are root or not ###
# This assumes you use a debian derivate, replace with yum, pacman etc.
aptget='sudo apt-get'
chsh='sudo chsh'