Skip to content

Instantly share code, notes, and snippets.

View flypiggy's full-sized avatar

李甘 flypiggy

  • fired
  • Beijing,China
View GitHub Profile
@UprototypeU
UprototypeU / 新鲜出炉的前端面试题
Created August 29, 2018 09:14
作者:Belinda 来自:segmentfault.com/a/1190000015916686
最近参加了几场面试,积累了一些高频面试题,我把面试题分为两类,一种是基础试题: 主要考察前端技基础是否扎实,是否能够将前端知识体系串联。一种是开放式问题: 考察业务积累,是否有自己的思考,思考问题的方式,这类问题没有标准答案。
基础题
题目的答案提供了一个思考的方向,答案不一定正确全面,有错误的地方欢迎大家请在评论中指出,共同进步。
怎么去设计一个组件封装
组件封装的目的是为了重用,提高开发效率和代码质量
低耦合,单一职责,可复用性,可维护性
前端组件化设计思路
@tyler-boyd
tyler-boyd / deploy.rb
Last active May 23, 2018 08:11 — forked from twetzel/deploy.rb
Compile assets locally with Capistrano 3.8.1 and Rails 5.1.1
# Clear existing task so we can replace it rather than "add" to it.
Rake::Task["deploy:compile_assets"].clear
namespace :deploy do
desc 'Compile assets'
task :compile_assets => [:set_rails_env] do
# invoke 'deploy:assets:precompile'
invoke 'deploy:assets:precompile_local'
invoke 'deploy:assets:backup_manifest'
@theorygeek
theorygeek / association_loader.rb
Last active October 31, 2023 07:15
Preloading Associations with graphql-batch
# frozen_string_literal: true
class AssociationLoader < GraphQL::Batch::Loader
attr_reader :klass, :association
def initialize(klass, association)
raise ArgumentError, "association to load must be a symbol (got #{association.inspect})" unless association.is_a?(Symbol)
raise ArgumentError, "cannot load associations for class #{klass.name}" unless klass < ActiveRecord::Base
raise TypeError, "association #{association} does not exist on #{klass.name}" unless klass.reflect_on_association(association)
@klass = klass
@jorgedavila25
jorgedavila25 / elastic_search_connection.rb
Last active March 11, 2020 14:03
Using Ruby's ElasticSearch gem that uses Kaminari for pagination and the Ruby GraphQL gem, this is a custom connection to bypass additional pagination. This assumes that you've already queried the correct paginated records from ElasticSearch and you're returning an `Elasticsearch::Model::Response` object.
class ElasticSearchConnection < GraphQL::Relay::BaseConnection
def has_next_page
!nodes.last_page?
end
def has_previous_page
!nodes.first_page?
end
def cursor_from_node(node)
@vjt
vjt / schema_format.rake
Last active July 20, 2018 16:48
Rails SQL schema load support for PostgreSQL. Put both files in `lib/tasks`.
import File.expand_path(File.dirname(__FILE__) + '/schema_format.rb')
namespace :db do
# Define PG environment utility methods
task :pg_env => :environment do
def pg_get_config
ActiveRecord::Base.configurations.fetch(Rails.env).tap do |config|
ENV['PGHOST'] = config['host'].to_s if config.key?('host')
ENV['PGPORT'] = config['port'].to_s if config.key?('port')
ENV['PGPASSWORD'] = config['password'].to_s if config.key?('password')
@lennart
lennart / eruby-coffee.vim
Created April 21, 2011 14:11
Coffee Script in ERB
autocmd BufNewFile,BufRead *.erb set filetype=eruby-coffee