Skip to content

Instantly share code, notes, and snippets.

@alexkojin
alexkojin / calendar.dart
Created February 9, 2021 15:20
Customer month cell flutter
/// Dart import
import 'dart:math';
import 'dart:ui' as ui;
///Package import
import 'package:flutter/material.dart';
///Date picker imports
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
class QuietActiveStorageLoggerMiddleware
def initialize(app)
@app = app
@regex = %r(\/rails\/active_storage)
end
def call(env)
if env['PATH_INFO'] =~ @regex
::Rails.logger.silence { @app.call(env) } # silences the logs!
else
#test
class ActiveStorageLoggerMute
class << self
def around(controller)
if controller.kind_of?(ActiveStorage::DiskController)
begin
old_logger = ActionController::Base.logger
ActionController::Base.logger = nil
Rails.logger.silence { yield }
ensure
@alexkojin
alexkojin / github.rb
Created April 11, 2017 07:06
Github Api wrapper
class Repo::Github
attr_accessor :account, :client
def initialize(account)
@account = account
end
def client
@client ||= Octokit::Client.new(access_token: account.access_token)
end
# redtube.com crawler
module Crawler::Redtube
class Parser < Crawler::BaseParser
scrape :video_id, ->(i) { i.url.split('/').reverse.first.to_i }
scrape :title, '.videoTitle'
scrape :author_name, '.video-details tr:eq(1) td:eq(2) a', alt: '.video-details tr:eq(1) td:eq(2) span'
scrape :views, '.video-details tr:eq(2) td:eq(2)', type: :integer
scrape :rating_percent, '.percent-likes', type: :integer
scrape :duration, '.video-duration'
scrape :uploaded_at, '.added-time', remove: /ADDED/, type: :date
@alexkojin
alexkojin / factory_girl_shared_resources.rb
Created November 21, 2016 09:21
FactoryGirl shared resources
# shared_factories/sequences
FactoryGirl.define do
sequence :email do |n|
"email#{n}@example.com"
end
sequence(:name) { |n| "store#{n}" }
end
@alexkojin
alexkojin / product_price_helper.rb
Last active October 13, 2016 08:39
Use class in rails helper
module ProductPriceHelper
# Render detailed product's price
def product_price(product)
ProductPrice.new(self, product).render
end
# render price for listing of products
def listing_price(product)
ProductPrice.new(self, product).render_for_listing
@alexkojin
alexkojin / the test task rails tracking user system
Last active August 29, 2015 13:56
The tracking system. The test task.
Implement simple rails store app with abilities to track user's activities
Features:
- product has title, description, price, tags
- pages: list of products, product's detail page
- search by products(use mysql)
- track user's clicks by the product in the search results
- every user should have unique tracking code. Use cookies to set it.
- save product id, user's ip, search keywords, user-agent, user's geo location, user's tracking code
- page: the list of tracking clicks
@alexkojin
alexkojin / layout.html.haml
Created August 16, 2013 20:28
layout_inner
- content_for :content do
%h2{style: 'text-align: left'}
Setup Wizard for #{@user.company_name}
= link_to 'Go Back To Customer Details Page', admin_user_path(@user), class: 'back-link'
.panel_layout{style: 'padding-bottom: 30px'}
#customer-setup
.wizard-steps.clearfix
- wizard_steps.each_with_index do |wizard_step, i|
= link_to wizard_path(wizard_step), class: "wizard-step #{active_class(wizard_step == step)}" do
@alexkojin
alexkojin / gist:4003333
Created November 2, 2012 18:18
amazon categories
[['Apparel​​', ​1036592​​],['​Appliances​​', ​2619525011​​],[ '​ArtsAndCrafts​​', ​2617941011],[ '​Automotive​​', ​15690151​​],[ '​Baby​​', ​165796011​​],[ '​Beauty​​', ​11055981​​],[ '​Books​​', ​1000​​],[ '​Classical​​', ​301668​​],[ '​Collectibles​​', ​4991425011​​],[ '​DigitalMusic​​', ​195208011​​],[ '​DVD​​', ​2625373011​​],[ '​Electronics​​', ​493964​​],[ '​ForeignBooks​​', ​''],[ '​Garden​​', ​''],[ '​GourmetFood​​', ​3580501​​],[ '​Grocery​​', ​16310101​​],[ '​HealthPersonalCare​​', ​3760931​​],[ '​Hobbies​​', ​''],[ '​Home​​', ​''],[ '​HomeGarden​​', ​285080​​],[ '​HomeImprovement​​', ​''],[ '​Industrial​​', ​228239​​],[ '​Jewelry​​', ​3880591​​],[ '​KindleStore​​', ​133141011​​],[ '​Kitchen​​', ​1063498​​],[ '​Lighting​​', ​''],[ '​Magazines​​', ​599872​​],[ '​Miscellaneous​​', ​10304191​​],[ '​MobileApps​​', ​2350149011​​],[ '​MP3Downloads​​', ​195211011​​],[ '​Music​​', ​301668​​],[ '​MusicalInstruments​​', ​11091801​​],[ '​OfficeProducts​​', ​1084128​​],[ '​OutdoorLiving​​', ​1063498​​],[ '​PCHa