Skip to content

Instantly share code, notes, and snippets.

@albb0920
albb0920 / extract_paths.rb
Created September 20, 2020 08:20
Extract AVUtils project file (.aup) referenced file paths
puts File.read(ARGV[1]).force_encoding('Shift_JIS').encode('UTF-8', invalid: :replace, undef: :replace, replace: '').scan(/.:\\.*?\0/).map{|x| x.sub(/[^a-z0-9]*$/, '')}.uniq
@albb0920
albb0920 / application_record.rb
Created March 22, 2019 12:32
Use PostgreSQL enum as rails enum
# Add the `native_enum` class method to your ApplicationRecord, like this,
# You can then use it in your model, and use postgres enum just like rails enum
#
# Eample:
# class Post < ApplicationRecord
# native_enum :status
# end
#
# Post.published.count => 0
class ApplicationRecord < ActiveRecord::Base
@function linear-calc($min, $max, $depend-expr, $depend-min, $depend-max) {
$range: $max - $min;
$grow-rate: $range / ($depend-max - $depend-min);
@return calc(
#{$min} + (#{$depend-expr} - #{$depend-min}) * #{$grow-rate}
);
}
$min-header-height: 40px;
@albb0920
albb0920 / reproduce.rb
Last active April 3, 2019 16:50
Unnecessary & slow query executed when using scope as condition
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.2.0' # use correct rails version
@albb0920
albb0920 / devise.zh-CN.yml
Created August 12, 2018 10:46
Devise 4.2.1 zh files
# Chinese (China) translations for Devise 4.2.1
# 4.2.0: By HealthGrid at https://gist.github.com/HealthGrid/2d702b38aa6ffe0233f27d3d5be9250f
# 4.2.1: By Artoria2e5 (this file)
# - Fixes pluralization problems (zh only takes "other")
# - Misc translation improvements, you know what these grammar things are.
# - Should be minor enough to claim CC0 for my changes.
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
zh-CN:
devise:
@albb0920
albb0920 / Gemfile
Last active July 12, 2017 16:18
等公車快來再下樓
# frozen_string_literal: true
source "https://rubygems.org"
gem "hashie"
@albb0920
albb0920 / cast_entire_desktop.applescript
Last active August 14, 2022 16:34
Cast entire desktop to Google Cast (Chromecast)
tell application "Google Chrome"
set need_delay to false
if not running then set need_delay to true
activate
if need_delay then delay 5
end tell
tell application "System Events"
tell process "Google Chrome"
-- Click View
@albb0920
albb0920 / lock
Created February 9, 2017 10:11
lock screen and turn display off
#!/bin/bash
export DISPLAY=:0
mate-screensaver-command -l
sleep 0.5
sudo xset dpms force off
@albb0920
albb0920 / snip.coffee
Created October 3, 2016 03:19
bootstrap tab thing
$('#settings-tabs a[data-target]').click (e)->
e.stopPropagation()
e.preventDefault()
history.pushState(null, null, $(this).attr('href'))
$('#settings-tabs .active').removeClass('active')
$(this).closest('li').addClass('active')
active_pane = $($(this).data('target'))
active_pane.closest('.tab-content').find('.tab-pane.active').removeC
@albb0920
albb0920 / poc.rb
Last active September 23, 2016 20:00
Inject method accessor for specific Hash instance PoC
# ====
# PoC: dot access to specific hash instance
# ===
x = {a: 1, b:2}
# override method_missing
original_method_missing = x.method(:method_missing)
x.define_singleton_method :method_missing do|name, *args, &block|
return x[name] if x.key? name