Inspired by dannyfritz/commit-message-emoji
See also gitmoji.
Commit type | Emoji |
---|---|
Initial commit | 🎉 :tada: |
Version tag | 🔖 :bookmark: |
New feature | ✨ :sparkles: |
Bugfix | 🐛 :bug: |
import { useState, useEffect, useRef } from 'react'; | |
import ResizeObserver from '@/modules/resize-observer'; | |
export default function useElementSize(element) { | |
const targetRef = useRef(); | |
const [state, setState] = useState({ width: undefined, height: undefined }); | |
useEffect(() => { | |
if (typeof element === 'function') { | |
targetRef.current = element(); |
import { useState, useEffect, useCallback } from 'react'; | |
import useThrottle from './use-throttle'; | |
import { useGlobalEventListener } from './use-event-listener'; | |
function getRect(element) { | |
if (element) return element.getBoundingClientRect(); | |
return { | |
width: 0, | |
height: 0, |
class AssociationLoader < GraphQL::Batch::Loader | |
def self.validate(model, association_name) | |
new(model, association_name) | |
nil | |
end | |
def initialize(model, association_name, preload_scope = nil) | |
@model = model | |
@association_name = association_name | |
@reflection = model.reflect_on_association(association_name) |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<style> | |
body { | |
display: flex; | |
justify-content: center; |
Inspired by dannyfritz/commit-message-emoji
See also gitmoji.
Commit type | Emoji |
---|---|
Initial commit | 🎉 :tada: |
Version tag | 🔖 :bookmark: |
New feature | ✨ :sparkles: |
Bugfix | 🐛 :bug: |
def self.set_flag( user_id, flag ) | |
# Making sure we only retry 2 times | |
tries ||= 2 | |
flag = UserResourceFlag.where( :user_id => user_id , :flag => flag).first_or_create! | |
rescue ActiveRecord::RecordNotUnique => e | |
Rollbar.error(e) | |
retry unless (tries -= 1).zero? | |
end |
def apply(scope, permission) | |
scope.where('all_permissions = true OR permissions @> ARRAY[?]::varchar[]', permission) | |
end |
require 'cgi' | |
def unicode_utf8(unicode_string) | |
unicode_string.gsub(/\\u\w{4}/) do |s| | |
str = s.sub(/\\u/, "").hex.to_s(2) | |
if str.length < 8 | |
CGI.unescape(str.to_i(2).to_s(16).insert(0, "%")) | |
else | |
arr = str.reverse.scan(/\w{0,6}/).reverse.select{|a| a != ""}.map{|b| b.reverse} | |
hex = lambda do |s| | |
(arr.first == s ? "1" * arr.length + "0" * (8 - arr.length - s.length) + s : "10" + s).to_i(2).to_s(16).insert(0, "%") |
class City < ActiveRecord::Base | |
def self.top_cities(order_by) | |
@top_cities ||= Hash.new do |h, key| | |
h[key] = where(top_city: true).order(key).to_a | |
end | |
@top_cities[order_by] | |
end | |
end |
Rails.application.routes.draw do | |
root 'application#index' | |
def draw(routes_name) | |
instance_eval(File.read(Rails.root.join("config", "routes", "#{routes_name}.rb"))) | |
end | |
# v1 接口 | |
draw :v1 |