Skip to content

Instantly share code, notes, and snippets.

View kaiwren's full-sized avatar

Sidu Ponnappa kaiwren

View GitHub Profile
@kaiwren
kaiwren / client.rb
Created June 28, 2023 07:43
Open AI API Access in Ruby
# gem 'wrest' in Gemfile
# optionally, `Wrest.logger = Rails.logger` in `config/initializers/wrest.rb`
module OpenAI
def self.base_uri
'https://api.openai.com/v1'.to_uri(
default_headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{ENV.fetch('OPENAI_KEY', nil)}"
@kaiwren
kaiwren / jira_csv_report.rb
Created September 6, 2022 18:21
Generate a simple summary from a Jira full excel CSV export
require 'csv'
csv_file = ARGV[0]
def section_heading(title)
"\n#{'-' * 10} #{title} #{'-' * 10}\n\n"
end
rows = CSV.read(csv_file)[1..-1].map do |r|
created_at = DateTime.parse(r[21])
Can Code Can't Code
Loves Coding Yes N/A
Hates Coding Maybe No
type Operation struct {
timeValue time.Time
s2IDLevel int64
s2ID int64
// ...
// ...
}
func (op operation) Perform() error {
surgeRepository := repository.NewSurgeRepository()
type Operation struct {
timeValue time.Time
s2IDLevel int64
s2ID int64
// ...
// ...
}
func (op operation) Perform(surgeRepository repository.SurgeRepository) error {
// ...
type Operation struct {
timeValue time.Time
s2IDLevel int64
s2ID int64
// ...
// ...
}
func (op operation) Perform(surgeRepository repository.SurgeRepository) error {
// ...
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/clone', __FILE__)
describe "Array#clone" do
it_behaves_like :array_clone, :clone
it "copies frozen status from the original" do
a = [1, 2, 3, 4]
b = [1, 2, 3, 4]
@kaiwren
kaiwren / object_clone_spec.rb
Created March 16, 2015 21:37
object dup_spec.rb
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/dup_clone', __FILE__)
describe "Object#clone" do
it_behaves_like :object_dup_clone, :clone
it "preserves frozen state from the original" do
o = ObjectSpecDupInitCopy.new
o2 = o.clone
o.freeze
@kaiwren
kaiwren / gameoflife.js
Created March 13, 2015 00:37
Compiled GoL via Opal
(function(undefined) {
if (typeof(this.Opal) !== 'undefined') {
console.warn('Opal already loaded. Loading twice can cause troubles, please fix your setup.');
return this.Opal;
}
// The Opal object that is exposed globally
var Opal = this.Opal = {};
// All bridged classes - keep track to donate methods from Object
@kaiwren
kaiwren / bm_factorial_inline_js.rb
Created March 9, 2015 04:10
Opal Microbenchmarks with inline js from github.com/kaiwren/redson
module Benchmarks
def self.fact_inline_js(n)
%x{
if(n > 1) {
return n * this.$fact_inline_js(n-1);
}
else {
return 1;
}
}