Skip to content

Instantly share code, notes, and snippets.

View ksugiarto's full-sized avatar

Kris Sugiarto ksugiarto

View GitHub Profile
@ksugiarto
ksugiarto / settings.json
Created April 3, 2018 09:44 — forked from bblanchon/settings.json
Sublime Text: Restore Quick Switch Project shortcut
{ "keys": ["ctrl+alt+p"], "command": "prompt_select_workspace" }
@ksugiarto
ksugiarto / report_controller.rb
Created October 23, 2016 16:50
Generate Prawn using custom routes
class ReportController < ApplicationController
def get_data
@customers = Customer.order(:name)
end
def sale
@sales = Sale
.where("EXTRACT(MONTH FROM sales.transaction_date)=EXTRACT(MONTH FROM CURRENT_DATE) AND EXTRACT(YEAR FROM sales.transaction_date)=EXTRACT(YEAR FROM CURRENT_DATE) AND sales.status IN (1)")
.order(:created_at).reverse_order
.pagination(params[:page])
@ksugiarto
ksugiarto / sale_controller.rb
Created October 23, 2016 16:46
Passing variable to prawn document
def show
@sale = Sale.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @sale }
format.pdf do
pdf = SaleIndividualPdf.new(@sale.id, view_context, ApplicationController.helpers.get_company_identity)
send_data pdf.render, filename: "#{I18n.t 'sale.sales_invoice'} #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}.pdf",
type: "application/pdf", :disposition => "inline"
@ksugiarto
ksugiarto / product.rb
Created July 1, 2016 07:00
Import function using Gem Roo on Model
def self.import(file)
spreadsheet = open_spreadsheet(file)
spreadsheet.sheets.each do |sheet| # looping all sheet
spreadsheet.default_sheet = "#{sheet}" # picking current sheet as default to be processing
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i| # looping all excel data
row = Hash[[header, spreadsheet.row(i)].transpose]
if row["CATEGORY"].present?
category_id = Category.find_by_name(row["CATEGORY"]).try(:id)
@ksugiarto
ksugiarto / _form.html.erb
Last active December 4, 2015 14:17
Rails AJAX Form Usage
<%= form_for(@category, :html => { :class => "form-horizontal" }, :remote => true) do |f| %>
<% if @category.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2>
<ul>
<% @category.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@ksugiarto
ksugiarto / readme.md
Created December 3, 2015 08:35 — forked from coolaj86/how-to-publish-to-npm.md
How to publish packages to NPM

Getting Started with NPM (as a developer)

If you haven't already set your NPM author info, now you should:

npm set init.author.name "Your Name"
npm set init.author.email "you@example.com"
npm set init.author.url "http://yourblog.com"

npm adduser

@ksugiarto
ksugiarto / ability.rb
Created November 26, 2015 07:04
Rails CanCan's Usage Example
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
can [:read, :update], User do |user_profile|
user_profile.id == user.id
end