Skip to content

Instantly share code, notes, and snippets.

View deivinsontejeda's full-sized avatar
🎯

Deivinson Tejeda deivinsontejeda

🎯
  • Santiago of Chile
View GitHub Profile
anonymous
anonymous / hammer
Created March 1, 2012 07:16
hammer prototype
#!/usr/bin/env ruby
# -*- encoding: UTF-8 -*-
# Derived from <http://stackoverflow.com/questions/5663519/namespacing-thor-commands-in-a-standalone-ruby-executable>
require 'rubygems'
require 'thor'
require 'thor/group'
module Hammer
var client = bayeux.getClient()
, channelKeyPrefix = "room:";
bayeux.bind('subscribe', function(clientId, channel){
redisClient.incr(channelKeyPrefix + channel, function(error, value){
client.publish(channel, {
event: 'user-change',
params: {
onlineUsers: value
}
@shu0115
shu0115 / file0.txt
Created February 25, 2013 06:19
Ruby 2.0.0-p0インストール(Mac OS X 10.8.2) ref: http://qiita.com/items/a24d1c8a1539f858137b
brew uninstall openssl
brew uninstall curl-ca-bundle
brew uninstall readline
#!/bin/bash
# inspired from: https://gist.github.com/vitobotta/2783513
threshold=300 # after 5min of uptime, a job is considered 'stuck', to kill
logfile=log/dead_workers_killed.log
function ps_etime_to_seconds() # cheers user000001 - http://stackoverflow.com/questions/14652445/parse-ps-etime-output-into-seconds#14653443
{
echo $1 | awk -F $':' -f <(cat - <<-'EOF'
@dqminh
dqminh / applause_formatter.rb
Last active December 18, 2015 04:59
rspec formatter that applause you when your tests pass
require "rspec/core/formatters/progress_formatter"
class ApplauseFormatter < RSpec::Core::Formatters::ProgressFormatter
def initialize(output)
super(output)
unless File.exists? "/tmp/applause.mp3"
p "Downloading applause for awesomeness"
system "wget http://www.soundjay.com/human/applause-1.mp3 -O /tmp/applause.mp3"
end
end
require 'json'
class JsonFormatter
METHODS = %w[start close stop start_dump dump_pending dump_failures dump_summary]
METHODS.each { |m| define_method(m) { |*a| } }
def initialize(out)
@output = out
@event_id = 0
@passed = true
@bkeepers
bkeepers / gist:6002211
Last active December 19, 2015 18:58
I'm looking for a better pattern for defining a method that takes a single object or an array of objects as an argument, does something with them, and then returns either a single object or an Array depending on what was passed to it.
def dress(dog_or_dogs)
dressed_dogs = Array(dog_or_dogs).map {|dog| DogSweater.new(dog) }
dog_or_dogs.respond_to?(:each) ? dressed_dogs : dressed_dogs.first
end
one_dog = dress(Dog.new)
all_my_dogs = dress([Dog.new, Dog.new, Dog.new])
# coding: utf-8
# Can ruby have method names have newlines/be crazy?
class BadKitty
FACE = "
|\\_/|
/ @ @ \\
( > º < )
`>>x<<´
@thelibrarian
thelibrarian / Fixing XCode Command Line Tools.md
Last active November 6, 2017 03:28
How to fix compile errors with the XCode command line tools on Mac OS X. Solves problems such as failing to find Framework header files (e.g. ruby.h).

The Problem

If you have installed the standalone Command Line Tools for XCode on your Mac (i.e. without having XCode.app installed), some of these tools can get a bit confused due to a couple of oversights on Apple's part in finalising the setup.

Note: all commands below will need to be run from an Administrator account, or by an account with appropriate permission in /etc/sudoers.

The Solution

1. Failing to Find Frameworks

Sometime when compiling against the preinstalled Frameworks (e.g. Ruby or Python), various tools will inexplicable fail to find header files that are quite clearly there. This is caused by the fact that no XCode has been selected for the command-line tools. Wait, I hear you cry, I don't have XCode installed! Indeed, but you nonetheless need to select one, and point it somewhere where the command line tools exist, like so

@rweald
rweald / simple-linear-regression.rb
Created August 29, 2012 19:13
Simple Linear Regression in Ruby
class SimpleLinearRegression
def initialize(xs, ys)
@xs, @ys = xs, ys
if @xs.length != @ys.length
raise "Unbalanced data. xs need to be same length as ys"
end
end
def y_intercept
mean(@ys) - (slope * mean(@xs))