Skip to content

Instantly share code, notes, and snippets.

View pokka's full-sized avatar
🌮
I may be slow to respond.

Pokka pokka

🌮
I may be slow to respond.
View GitHub Profile
@pokka
pokka / supervisor.conf
Created February 28, 2017 02:33
supervisor example conf file
[unix_http_server]
file=/tmp/supervisor.sock
;username = dongwm
;password = 123
[inet_http_server]
port = 0.0.0.0:5000
username = dongwm
password = 123
(function() {
// Adding upload button to Trix toolbar on initialization
document.addEventListener('trix-initialize', function(e){
trix = e.target;
toolBar = trix.toolbarElement;
// Creation of the button
button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute("class", "attach");
@pokka
pokka / postForm.js
Created August 10, 2016 02:41
javascript es6 post data via form
function postForm(path, params = {}) {
const form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', path);
Object.keys(params).forEach((key) => {
if (params.hasOwnProperty(key)) {
const hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'hidden');
hiddenField.setAttribute('name', key);
hiddenField.setAttribute('value', params[key]);
@pokka
pokka / wechat-browser-detect.js
Last active May 31, 2017 01:49 — forked from cary929/wechat-browser-detect.js
JavaScript 判断是否微信内置浏览器
// 使用 userAgent 判断是否微信内置浏览器
if( navigator.userAgent.toLowerCase().indexOf('micromessenger') > -1 || typeof navgator.wxuserAgent !== "undefined" ) {
return true;
}
@pokka
pokka / rails_skip_validate_callback.rb
Created April 21, 2016 08:58
Rails skip validates and callbacks, temporary
module ActiveRecord::Persistence::ClassMethods
def create!(attributes = nil, &block)
if attributes.is_a?(Array)
attributes.collect { |attr| create!(attr, &block) }
else
object = new(attributes, &block)
[:save,:create].each { |cb| object.class.reset_callbacks cb }
object.save(validate: false)
object
@pokka
pokka / model_cache_key.rb
Created April 12, 2016 05:13
ActiveRecord cache key
module ActiveRecord
class Base
def self.cache_key
Digest::MD5.hexdigest "#{scoped.maximum(:updated_at).try(:to_i)}-#{scoped.count}"
end
end
end
@pokka
pokka / execute_statements.rb
Last active April 12, 2016 05:10
run multiple statments in rails migrate
sql = File.read(sql_file)
statements = sql.split(/;$/)
statements.pop if statements.last.blank?
ActiveRecord::Base.transaction do
statements.uniq.each { |statement| execute(statement.gsub(/\n/, '')) }
end
@pokka
pokka / fl.sh
Created March 17, 2016 03:08
finding-the-largest-files-directories
find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
@pokka
pokka / Ruby STRFTIME conversion formats.rb
Last active September 7, 2015 03:06 — forked from akshaymohite/Ruby STRFTIME conversion formats.rb
Ruby script to print out strftime conversion format options and outputs
# Function to print strftime results
def print_strftime_formats(a,cur_date)
a.each do |format|
b = "%#{format}"
output = cur_date.strftime(b)
puts "t.strftime('#{b}'), => #{output}"
end
end
a = ('a'..'z').to_a
@pokka
pokka / i_rb
Created June 2, 2015 07:14
ruby-install
#!/bin/sh
_ver='2.1.6'
if [ -z "$V" ]; then
_ver='2.1.6'
else
_ver=$V
fi
ruby-install --rubies-dir /usr/local/rubies ruby $_ver