Skip to content

Instantly share code, notes, and snippets.

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

Andy Wang yorzi

🏠
Working from home
  • Xi'an, China
  • 19:58 (UTC +08:00)
View GitHub Profile
@yorzi
yorzi / rails_exercise.rb
Last active September 16, 2023 02:29 — forked from rhelsing/rails_exercise.rb
Rails Exercise by Andy Wang
# Background:
# The following code works but I have intentionally introduced issues to make it inefficient.
# UserEvents are created for every interaction a user has in the system. It stores what employer, partner and
# controller they were on. When there were 10 users and only a little bit of traffic, this would run quickly.
# But now with 10,000 users and months of traffic - (millions of user events), this code would be very inefficient.
# Instructions:
# 1. Please make this code more efficient through refactoring so that it can run at a greater scale,
# along with adding some comments to improve the readability.
# 2. Please explain what the variable 'distinct_groups' will contain by the end of the execution and what
@yorzi
yorzi / create-ruby-gem-that-adds-rake-tasks.md
Created May 8, 2023 03:28 — forked from ntamvl/create-ruby-gem-that-adds-rake-tasks.md
How to create a Ruby gem that adds Rake tasks

How to create a Ruby gem that adds Rake tasks

Create a gem

One way to do this is to use bundler to scaffold our gem:

bundler gem my_gem

Add rake tasks to our gem

I prefer to put tasks meant to manage the gem itself in lib/tasks, and tasks the gem is meant to provide to gem users in lib/my_gem/tasks.

@yorzi
yorzi / #ChatGPT Streaming.md
Created May 5, 2023 03:19 — forked from alexrudall/#ChatGPT Streaming.md
ChatGPT streaming with ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind!

How to add ChatGPT streaming to your Ruby on Rails 7 app!

This guide will walk you through adding a ChatGPT-like messaging stream to your Ruby on Rails 7 app using ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind. All code included below!

Alt Text

First, add the ruby-openai gem! Needs to be at least version 4. Add Sidekiq too.

@yorzi
yorzi / readme.md
Created August 18, 2021 01:52 — forked from maxivak/readme.md
Integrating Gem/Engine and Main Rails App
@yorzi
yorzi / index.html
Created February 17, 2020 08:52 — forked from tiffany352/index.html
Twitter archive browser
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Twitter Archive Browser</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<style>
@yorzi
yorzi / grape_api_sample.rb
Created March 29, 2011 12:33
a well documented ruby api based on GrapeAPI.
require 'grape'
module My
class API < Grape::API
prefix 'api'
## params key list
#################################################################################################################
# 1. login
# 2. sign
@yorzi
yorzi / GA-form-tracking.js
Created October 13, 2014 14:14
Testing for GA form/event tracking
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55682644-1', 'auto', {
'allowLinker': true
});
ga('require', 'linker');
@yorzi
yorzi / api_key_generator.rb
Created March 29, 2011 03:03
api key(or any other kind of key) generator via ruby.
class KeyGenerator
require "digest/sha1"
def self.generate(length = 10)
Digest::SHA1.hexdigest(Time.now.to_s + rand(12341234).to_s)[1..length]
end
end
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'
require 'mina/puma'
set :application_name, 'myapp'
set :domain, 'myapp.com'
set :deploy_to, '/home/admin/myapp'
set :repository, 'git@github.com:lnikell/myapp.git'
@yorzi
yorzi / install_postgresql.sh
Created May 22, 2017 06:54 — forked from dstroot/install_postgresql.sh
Install PostgreSQL on Amazon AMI
#!/bin/bash
###############################################
# To use:
# https://raw.github.com/gist/2776351/???
# chmod 777 install_postgresql.sh
# ./install_postgresql.sh
###############################################
echo "*****************************************"
echo " Installing PostgreSQL"
echo "*****************************************"