Skip to content

Instantly share code, notes, and snippets.

View 3014zhangshuo's full-sized avatar
🎯
Coding

张硕 3014zhangshuo

🎯
Coding
View GitHub Profile
class DataModel
include Enumerable
def initialize data
@data = data
end
def each
@data.each { |x| yield x }
end
class Solution
def reverse_integer(x)
# for the last result
sign = x < 0 ? -1 : 1
x_clone = x.abs.dup
x_result = 0
while x_clone > 0
x_result = (x_result * 10) + x_clone % 10
@3014zhangshuo
3014zhangshuo / ticket_template_use_scope.rb
Last active August 13, 2020 08:16
没有使用到的代码
def use_scope_info
%i[klass content_key attributes_query current_usager_ids]
.each_with_object(ActiveSupport::OrderedOptions.new) do |k, object|
object[k] = USE_SCOPE_INFO.dig(k, usager_type.to_sym)
end
end
USE_SCOPE_INFO = {
klass: {
agents: Agent,
@3014zhangshuo
3014zhangshuo / fallthrough.rb
Created August 5, 2020 01:45 — forked from havenwood/fallthrough.rb
Fallthrough case statement in Ruby
value = :initial
catch :redo do
case value
when :initial
puts 'initial'
value = :changed
redo
when :changed
puts 'changed'
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
npm config delete proxy
@3014zhangshuo
3014zhangshuo / solution.java
Created June 16, 2020 01:47
Euclid's algorithm
public static int gcd(int p, int q)
{
if (q == 0) return p;
int r = p % q;
return gcd(q, r);
}
@3014zhangshuo
3014zhangshuo / translate.js
Last active June 16, 2020 10:49
自动翻译 rails 多语言文件
const fs = require('fs')
const translate = require('google-translate-api')
const langCodeFileMap = {
bn: 'bn',
en: 'en-us',
de: 'de',
el: 'el',
es: 'es',
fr: 'fr',
@3014zhangshuo
3014zhangshuo / signal_catching.rb
Created June 1, 2020 06:12 — forked from sauloperez/signal_catching.rb
How to catch SIGINT and SIGTERM signals in Ruby
# Signal catching
def shut_down
puts "\nShutting down gracefully..."
sleep 1
end
puts "I have PID #{Process.pid}"
# Trap ^C
Signal.trap("INT") {
@3014zhangshuo
3014zhangshuo / mysql_downgrade.txt
Created April 16, 2020 09:33 — forked from 6temes/mysql_downgrade.txt
Downgrade MySQL version with brew
# Kill rails server and guard
bin/spring stop
brew services stop mysql
brew uninstall mysql
brew install [email protected]
brew link [email protected] --force
brew services start [email protected]
rbenv uninstall 2.3.3
rbenv install 2.3.3
gem install bundle
@3014zhangshuo
3014zhangshuo / swipe-left.css
Last active August 8, 2020 07:14
模仿APP左滑出删除按钮
.list {
overflow: hidden;
}
[data-swipe="left"] {
width: 120%;
overflow: hidden;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;