Skip to content

Instantly share code, notes, and snippets.

View kivanio's full-sized avatar
🏠
Working from home

Kivanio Barbosa kivanio

🏠
Working from home
View GitHub Profile
@kivanio
kivanio / get_attachment_id.rb
Created December 22, 2016 17:52 — forked from captproton/get_attachment_id.rb
June 2014 Gmail API list emails with PDF attachements
# Copyright (C) 2012 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
require "nkf"
require 'google/apis/gmail_v1'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'rmail'
require 'fileutils'
class GmailMailer
@kivanio
kivanio / emailed_zip_file_extractor.rb
Created December 22, 2016 17:50 — forked from jkotchoff/emailed_zip_file_extractor.rb
Rails example of how to connect to the Gmail API using Ruby and download a Zip File attachment and then unzip contents from the zip archive
class EmailedZipFileExtractor
# This class downloads an email from gmail and extracts a file out of a .zip attachment
require 'google/apis/gmail_v1'
require 'googleauth'
require 'zip'
# These credentials come from creating an OAuth Web Application client ID
# in the Google developer console
#
@kivanio
kivanio / betfair_request_ssoid.rb
Created December 22, 2016 17:24 — forked from sergio1990/betfair_request_ssoid.rb
Request ssoid for accesing API-NG betfair.com
require "net/https"
require "uri"
crt = File.read("client-2048.crt")
key = File.read("client-2048.key")
app_key = "YOUR_APP_KEY"
username = "YOUR_USERNAME"
password = "YOUR_PASSWORD"
@kivanio
kivanio / test.rb
Created December 20, 2016 11:08 — forked from SamSaffron/test.rb
require 'net/http'
require 'openssl'
def test_connection(ip_address, uri, delays)
Net::HTTP.start(ip_address, uri.port,
use_ssl: true,
verify_mode: OpenSSL::SSL::VERIFY_NONE,
keep_alive_timeout: 50
) do |http|
while true
@kivanio
kivanio / converter_script.rb
Created October 24, 2016 19:34 — forked from kalmanh/converter_script.rb
Ruby script to convert .mdb db file into .csv
# Export data from Microsoft Access .mdb database into .csv files
# using https://github.com/brianb/mdbtools
# Install with homebrew - "brew install mdbtools"
class ConverterScript
tables = `mdb-tables -d , your_db_name.mdb`.chop.split(",")
tables.each do |table|
exists = system("mdb-export your_db_name.mdb '#{table}'")
`mdb-export your_db_name.mdb '#{table}' > #{table.gsub(" ", "_")}.csv` if exists
library(dplyr)
library(ggplot2)
library(httr)
setwd("C:/Dropbox/Projects/20160206_Soccer_Scores")
if (!file.exists("20160206_Soccer_Scores.csv.gz")) {
cat("must reread")
}
class Customer < ActiveRecord::Base
after_create :send_welcome_email, unless: :auto_registered?
has_one :auto_created, dependent: :destroy
private
def send_welcome_email
CustomerMailer.welcome_email(self).deliver
end
def auto_registered?
class CustomersController < ApplicationController
# …
def create
@customer = Customer.new(customer_params)
respond_to do |format|
if @customer.save
format.html { redirect_to @customer,
notice: 'Customer was successfully created.' }
format.json { render :show, status: :created,
class CustomersController < ApplicationController
# …
def create
if auto_create_request?
@customer = Customer.auto_create(customer_params)
else
@customer = Customer.register(customer_params)
end
respond_to do |format|