Skip to content

Instantly share code, notes, and snippets.

Yuki Nishijima yuki24

Block or report user

Report or block yuki24

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@yuki24
yuki24 / routes_ast.rb
Created Jul 22, 2019
Rails routes AST access
View routes_ast.rb
#
# Run this with `rails runner route_ast.rb`
#
Rails.application.routes.routes.each do |route|
ast = route.ast
# do stuff with AST...
end
@yuki24
yuki24 / grid-col.ts
Last active Apr 6, 2019
grid-elements
View grid-col.ts
import { LitElement, html, customElement } from '@polymer/lit-element'
const NUMBER_OF_GRID = 12
const generateCss = (screenSize) => {
return Array.apply(0, Array(NUMBER_OF_GRID)).map((element, index) => index + 1).map(num =>
`
:host([${screenSize}="${num}"]) {
-ms-flex-preferred-size: ${(100 / NUMBER_OF_GRID) * num}%;
flex-basis: ${(100 / NUMBER_OF_GRID) * num}%;
@yuki24
yuki24 / artemis.rb
Created Feb 2, 2019
graphql-client vs artemis
View artemis.rb
# config/graphql.yml
development:
sw_api:
url: "https://example.com/graphql"
schema_path: "path/to/schema.json"
# app/operations/sw_api/hero.graphql
query($episode: Episode) {
hero(episode: $episode) {
name
@yuki24
yuki24 / andpush_benchmark.rb
Created Apr 14, 2018
Example of the Andpush gem and benchmark
View andpush_benchmark.rb
require 'benchmark/ips'
require 'andpush'
require 'fcm'
server_key = ENV.fetch('FCM_TEST_SERVER_KEY')
DEVICE_TOKEN = ENV.fetch('FCM_TEST_REGISTRATION_TOKEN')
FCM_CLIENT = FCM.new(server_key)
PAYLOAD_FOR_FCM = { dry_run: true, notification: { title: "u", body: "y" } }
View benchmark_spell_checker.rb
require 'benchmark_driver'
Benchmark.driver do |x|
x.prelude <<~RUBY
METHODS = ''.methods
INPUT = 'start_with?'
spell_checker = DidYouMean::SpellChecker.new(dictionary: METHODS)
RUBY
@yuki24
yuki24 / object_mapper.rb
Last active Jan 30, 2018
better JSON serializer that returns an object with pre-defined attribute readers
View object_mapper.rb
require 'json'
require 'securerandom'
require 'delegate'
class ObjectMapper < SimpleDelegator
def self.parse(json_string, **opts)
JSON.parse(json_string, object_class: JsonHash, create_additions: true, create_id: JSON_CREADE_ID, **opts)
end
JSON_CREADE_ID = SecureRandom.uuid.freeze
View andpush_vs_fcm.rb
require 'benchmark/ips'
require 'andpush'
require 'fcm'
server_key = ENV.fetch('FCM_TEST_SERVER_KEY')
DEVICE_TOKEN = ENV.fetch('FCM_TEST_REGISTRATION_TOKEN')
FCM_CLIENT = FCM.new(server_key)
PAYLOAD_FOR_FCM = { dry_run: true, notification: { title: "u", body: "y" } }
View error_page_spec.rb
def with_exceptions_app(enabled = true)
org_show_detailed_exceptions = Rails.application.env_config['action_dispatch.show_detailed_exceptions']
org_show_exceptions = Rails.application.env_config['action_dispatch.show_exceptions']
# This overrides the cached setting in Rails.application.config.consider_all_requests_local
Rails.application.env_config['action_dispatch.show_detailed_exceptions'] = !enabled
# Render templates instead of raising exceptions.
Rails.application.env_config['action_dispatch.show_exceptions'] = enabled
@yuki24
yuki24 / json_with_synbolize_names.rb
Created Jan 13, 2017
JSON with the symbolize_name: true option
View json_with_synbolize_names.rb
require 'json'
require 'open-uri'
require 'benchmark/ips'
require 'memory_profiler'
json = open('https://network.pivotal.io/api/v2/products').read
Benchmark.ips do |x|
x.report('symbolize_names: false') { JSON.parse(json) }
x.report('symbolize_names: true') { JSON.parse(json, symbolize_names: true) }
@yuki24
yuki24 / incorrect_corrections.yml
Last active Aug 29, 2015
A list of Incorrect corrections generated by did_you_mean's spell checker
View incorrect_corrections.yml
#- correct_word: incorrect_word(user input)
# result:
# - list_of_candidates
---
- absence: absense
result:
- absences
- absents
- absence
- absentee
You can’t perform that action at this time.