Skip to content

Instantly share code, notes, and snippets.

View sbusso's full-sized avatar
🤖
Crafting with AI friends

Stéphane Busso sbusso

🤖
Crafting with AI friends
View GitHub Profile
require 'rubygems'
require 'eventmachine'
require 'em-http' # gem install em-http-request
require 'yajl' # gem install yajl-ruby
module ChatClient
def post_init
@name = "anonymous_#{ChatClient.client_num+=1}"
@sid = ChatClient.channel.subscribe(method(:send_msg))
@buf = ''
new_object = OtherDatabase::NewClass1.new
...
result = OtherDatabase::NewClass1.find(:all)
# rake task to export comments from typo to disqus
require 'disqus'
require 'disqus/api'
require 'disqus/author'
require 'disqus/forum'
require 'disqus/post'
require 'disqus/thread'
namespace :export do
# Author: Stephane Busso based Toby DiPasquale <toby@cbcg.net> Jekyll import and other disqus import
require 'fileutils'
require 'rubygems'
require 'sequel'
require 'rake'
namespace :import
desc "import posts"
task :post do
# this SQL *should* work for both MySQL and PostgreSQL, but I haven't
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
# - a browser with WebSocket support
#
# Usage:
# ruby redis_pubsub_demo.rb
#
<!-- This is a Node+WebSocket powered demo to sync videos
across different browsers. This file is the client,
the other one is the Node server. Powered by Node and
http://github.com/miksago/node-websocket-server -->
<style>
.inactive { display: none; }
.active { display: block; }
</style>
<script>
generators = []
puts 'Spinning up a new app, captain!'
devise = yes?('Use Devise? (yes/no)')
jquery = yes?('Use jQuery? (yes/no)')
jquery_ui = yes?('Use jQuery UI? (yes/no)') if jquery
mongoid = yes?('Use mongoid? (yes/no)')
haml = yes?('Use haml? (yes/no)')
rspec = yes?('Use Rspec? (yes/no)')
@sbusso
sbusso / redis-ubuntu
Created March 29, 2011 08:27
Set redis on ubuntu & resque
# install redis
# cp file /etc/redis/redis.conf
# create file /etc/init.d/redis
# create user and group redis
$ sudo update-rc.d redis
bundle exec resque-web -e production -s thin -L config/initializers/resque.rb
bundle exec resque-web -K
rake resque:scheduler INITIALIZER_PATH=config/initializers/resque.rb
QUEUE=cron rake environment resque:work
@sbusso
sbusso / async_job.rb
Created March 30, 2011 09:32
A simple module to add async method to your activerecord or other ruby objects
module Resque
module AsyncJob
@@_queue= :default
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
# Set the default queue. chain method
def queue(new_queue = nil)
@sbusso
sbusso / Redis_Pubsub_Client.rb
Created March 31, 2011 19:07 — forked from gautamrege/Redis_Pubsub_Client.rb
Redis Pubsub Client
require 'redis'
require 'multi_json'
class PubSubRedis < Redis
def initialize(options = {})
@timestamp = options[:timestamp].to_i || 0 # 0 means -- no backlog needed
super
end