Skip to content

Instantly share code, notes, and snippets.

View PrimeTimeTran's full-sized avatar
🎯
Focusing

Loi Tran PrimeTimeTran

🎯
Focusing
View GitHub Profile
<%= form_for @ticket do |f| %>
<div class="row">
<div class="col-md-11 col-md-offset-1">
<table class="table">
<th>Ticket Type</th>
<th>Unit Price</th>
<th>Quantity</th>
<% @event.ticket_types.each do |type| %>
<tr>
def create
@comment = current_user.comments.create!(comment_params)
@parent = params[:comment][:parent_id]
PostMailer.commented_post(@comment.post.user_id, current_user).deliver_now unless Post.mine?(@comment.post.id, current_user)
Rb::PhotoUploadService.upload(current_user.id, self.class, @comment.id, params[:comment][:photo]) if params[:comment][:photo]
respond_to do |format|
if @comment.save
format.html { redirect_back(fallback_location: root_path) }
format.js
// PURPOSE:
// to prevent green dot from going grey on simple user navigations to different parts of the app
// PROBLEM:
// if the user 'x's the tab of their browser, this ActionCable method never runs, thus the user is always online
disconnected: function() {
setTimeout(function () {
if (!App.cable) {
this.perform("disappear");
}
[obj1, obj2, obj3, ...].group_by{|x| x.created_at.strftime("%Y-%m-%d")}
def five_minute_prices
time = Time.zone.now.end_of_day
first_price = Price.first.created_at
prices = {}
while first_price < time
earlier_time = time - 300
later_time = time
prices[time] = []
r = Range.new(earlier_time, later_time)
class Price < ApplicationRecord
module Scopes
def daily
created_at.to_date.to_s(:db)
end
def weekly
where('created_at >= ?', 1.week.ago)
end
# frozen_string_literal: true
class Price < ApplicationRecord
module Scopes
def daily
created_at.to_date.to_s(:db)
end
def weekly
where('created_at >= ?', 1.week.ago)
def create_candlestick(group)
{
date: group[0],
open: opening_price(group[1]),
close: closing_price(group[1]),
low: lowest_price(group[1]),
high: highest_price(group[1])
}
end
def self.most_recent
{ data: { base: 'BTC', currency: 'USD', amount: last.price } }
end
def self.recent_prices(market_id = 1, coin = 1)
search = query_elastic(market_id, coin)
return [] unless search.aggregations.present?
time_intervals = search.aggregations.dig('five_time_intervals', 'buckets')
time_intervals.inject([]) do |interval, i|
# Comment Form
<%= form_for [@post, Comment.new] do |f| %>
<%= f.text_field :body, placeholder: "Comment", class: "form-control", required: true, size: "30x10" %>
<%= f.submit %>
<% end %>
# Post Controller
def show
@post = Post.find(params[:id])
end