Skip to content

Instantly share code, notes, and snippets.

View luizkowalski's full-sized avatar
:atom:
bug fixes and performance improvements

Luiz Eduardo Kowalski luizkowalski

:atom:
bug fixes and performance improvements
View GitHub Profile
@technoweenie
technoweenie / github_oauth_busy_developer_guide.md
Created May 30, 2010 18:34
GitHub OAuth Busy Developer's Guide

GitHub OAuth Busy Developer's Guide

This is a quick guide to OAuth2 support in GitHub for developers. This is still experimental and could change at any moment. This Gist will serve as a living document until it becomes finalized at Develop.GitHub.com.

OAuth2 is a protocol that lets external apps request authorization to private details in your GitHub account without getting your password. All developers need to register their application before getting started.

Web Application Flow

  • Redirect to this link to request GitHub access:
@macek
macek / 20101004063749_create_photos.rb
Created October 4, 2010 22:38
How to save uploaded files to your database in Rails
# db/migrate/20101004063749_create_photos.rb
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.string :name, :null => false
t.binary :data, :null => false
t.string :filename
t.string :mime_type
t.timestamps
@zumbojo
zumbojo / bijective.rb
Created July 9, 2011 22:09
Simple bijective function (base(n) encode/decode)
# Simple bijective function
# Basically encodes any integer into a base(n) string,
# where n is ALPHABET.length.
# Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047
ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//)
# make your own alphabet using:
# (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join
@rakasaka
rakasaka / gist:1169341
Created August 24, 2011 21:45
Unsupervised topic modeling in Ruby using LDA
require 'lda-ruby'
corpus = Lda::Corpus.new
corpus.add_document(Lda::TextDocument.new(corpus, "a lion is a wild feline animal", []))
corpus.add_document(Lda::TextDocument.new(corpus, "a dog is a friendly animal", []))
corpus.add_document(Lda::TextDocument.new(corpus, "a cat is a feline animal", []))
lda = Lda::Lda.new(corpus)
lda.verbose = false
lda.num_topics = (2)
lda.em('random')
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@Chavao
Chavao / gist:1974196
Created March 4, 2012 18:08
Busca de endereço por CEP
<?
function getCEP($psCEP)
{
echo utf8_encode(urldecode(trim(@file_get_contents('http://cep.republicavirtual.com.br/web_cep.php?cep='.urlencode($psCEP).'&formato=javascript'))));
// Retorna var resultadoCEP = { 'uf' : 'UF', 'cidade' : 'Cidade', 'bairro' : 'Bairro', 'tipo_logradouro' : 'Avenida', 'logradouro' : 'Logradouro', 'resultado' : '1', 'resultado_txt' : 'sucesso - cep completo' }
}
?>
$ echo 'export PATH=$PATH:$HOME/.gem/ruby/1.9.1/bin' >> ~/.bashrc && . ~/.bashrc
@tmcallister
tmcallister / faye.rb
Created May 23, 2012 23:52
Faye with nginx config
FAYE_TOKEN = 'secretToken'
if defined? Rails
if Rails.env == 'development'
FAYE_URI = "http://#{APP_CONFIG[:nameremoved_service][:host]}:9292/faye"
else
FAYE_URI = "https://#{APP_CONFIG[:nameremoved_service][:host]}/faye"
end
@massahud
massahud / 1-README.md
Last active June 28, 2017 14:15
flyingsaucer xhtml to pdf servlet filter

Filter to generate PDF from Servlet dynamic pages

This filter intercepts the response and runs Flying Saucer ITextRenderer on it, returning a pdf instead.

Configuration

Just put the filter on your code and configure the url patterns where it will run on web.xml. The filtered pages will return as pdf documents.

@rxin
rxin / ramdisk.sh
Last active December 13, 2023 02:40
ramdisk create/delete on Mac OS X.
#!/bin/bash
# From http://tech.serbinn.net/2010/shell-script-to-create-ramdisk-on-mac-os-x/
#
ARGS=2
E_BADARGS=99
if [ $# -ne $ARGS ] # correct number of arguments to the script;
then