Skip to content

Instantly share code, notes, and snippets.

View Agowan's full-sized avatar

Niklas Lundgren Agowan

  • Boulebar
  • Stockholm Sweden
View GitHub Profile
@Agowan
Agowan / Install.md
Last active May 4, 2020 11:04
Install magento in production (external MySQL)
  1. Make sure your system is up to date
sudo apt update && sudo apt upgrade -y
  1. Create user
sudo useradd -m -U -r -d /opt/magento magento && sudo chmod 750 /opt/magento

See this tutorial to add repos and upgrade to new versions: https://thishosting.rocks/install-php-on-ubuntu/

echo "installing"
@Agowan
Agowan / api_controller.rb
Created September 12, 2017 12:11
Slim api with rails
# frozen_string_literal: true
module Api
class BaseController < ActionController::Metal
include ActiveSupport::Rescuable
# Add if you want to have force ssl
# include ActionController::ForceSSL
# Add if you want callbacks i.e. before_action
@Agowan
Agowan / api_controller.rb
Created August 22, 2016 11:26
Slim api base controller
# frozen_string_literal: true
module Store
class ApiController < ActionController::Metal
include ActionController::ForceSSL
include ActiveSupport::Rescuable
include AbstractController::Callbacks
include Authority::Controller
include Sorcery::Controller
include ActionController::Helpers
class ApiController < ActionController::Metal
include ActionController::HttpAuthentication::Token::ControllerMethods
include AbstractController::Rendering
include ActionController::Rendering
include ActionController::Renderers::All
include ActionController::ForceSSL
include ActionController::StrongParameters
include ActionController::Serialization
include ActiveSupport::Rescuable
include ActionController::Head
var validatePnr = function(str) {
if(str.length != 12)
return false;
var date_string = [str.slice(0,4),'-',str.slice(4,6),'-',str.slice(6,8)].join('');
if(isNaN(Date.parse(date_string)))
return false;
str = str.slice(2,12);
@Agowan
Agowan / reports_controller.rb
Created June 3, 2015 08:48
Renaming files on response for expiring url.
# encoding: UTF-8
class Report < ActiveRecord::Base
has_attached_file :file, :path => "/:statistic_report_root/:year/:id_partition.pdf"
end
def data
@data ||= File.read pdf_template_path
end
def pdf_template_path
@tmp_path ||= @pdf_template.template.tap { |u| u.cache_stored_file! }.path
end
def cleanup
File.delete(pdf_template_path) if File.exist?(pdf_template_path)
@Agowan
Agowan / string_file.rb
Created May 6, 2015 12:38
Override StringIO content type
# encoding: utf-8
class StringFile < StringIO
def initialize(file_content, file_name, file_type)
super(file_content)
@file_name = file_name
@file_type = file_type
end
@Agowan
Agowan / email.rb
Created May 6, 2015 12:32
Store raw email in attachment with rails
# encoding: UTF-8
class Email < ActiveRecord::Base
has_attached_file :raw
after_save :remove_file
# ===========================================================================
# Public instance methods