Skip to content

Instantly share code, notes, and snippets.

View kaorukobo's full-sized avatar

Kaoru Shirai kaorukobo

  • Hiroshima, Japan
View GitHub Profile
require "minitest/autorun"
module HasConstant
CONST = "const"
end
# ================================================
# Pass:
class TheTest1 < Minitest::Test
include HasConstant
@kaorukobo
kaorukobo / rollback-bundle-install.sh
Created April 23, 2017 11:51
This oneliner rollbacks (undos) package installations by `bundler install`. Copy bundler's output contains `Installing PACKAGE VER.SI.ON` lines into bunder_output.log then execute this.
ruby -e '$<.scan(/Installing (\S+) (\S+)/).each do |pkg, ver| system "gem uninstall -v #{ver} #{pkg}"; end' bundler_output.log
@kaorukobo
kaorukobo / wp-config-error-handling.php
Last active March 19, 2017 08:58
How to Prevent WordPress from stopping rendering without any error mesages, on PHP 7.1+Wordpress (4.7.2)
# Put these on wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
function custom_exception_handler($exception)
{
$logmsg = "Uncaught exception: " . $exception->getMessage() . "\n" . $exception->getTraceAsString() . "\n";
trigger_error($logmsg, E_ERROR);
if (WP_DEBUG) {
echo($logmsg);
public function stdclass_to_array($stdclass) {
return json_decode(json_encode($stdclass), true);
}
@kaorukobo
kaorukobo / Rails_ignore_normalize_params_TypeError_expected_Hash_for_param.rb
Last active August 29, 2015 13:56
If you make the Rails application as a proxy to other web application, you often meet problems with parameters: "TypeError: expected Hash (got String) for param ". If you want to make Rails(Rack) to ignore these errors, this code helps. Put this in RAILS_ROOT/initializers folder. My environemnt is Ruby 2.0.0p247 + Rails 3.2.12 + Rack 1.4.5.
module Rack::Utils
# to avoid this error:
# home/rack-1.4.5/lib/rack/utils.rb line 127
# raise TypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params_hash_type?(params[k])
unless defined? normalize_params_without_error_passthru
alias normalize_params_without_error_passthru normalize_params
module_function :normalize_params_without_error_passthru
end
def normalize_params(params, *args)
@kaorukobo
kaorukobo / gist:3151940
Created July 20, 2012 17:10
post() error with httpful
require('httpful/bootstrap.php');
$resp = \Httpful\Request::post($url)->sendsJson()->body($json)->send();
<b>Fatal error</b>:
Uncaught exception 'Exception' with message 'Unable to parse response code from HTTP response due to malformed response' in httpful/src/Httpful/Response.php:128
Stack trace:
#0 httpful/src/Httpful/Response.php(38): Httpful\Response-&gt;_parseCode('HTTP/1.1 100 Co...')
#1 httpful/src/Httpful/Request.php(175): Httpful\Response-&gt;__construct('HTTP/1.1 200 OK...', 'HTTP/1.1 100 Co...', Object(Httpful\Request))
@kaorukobo
kaorukobo / activerecord_hack__association_auto_class_name_with_parent_module.rb
Created June 25, 2012 13:11
Hack for ActiveRecord: to avoid "NameError: uninitialized constant" on Rails-3.1.3 + active_scaffold 3.* (append parent module name to association's class_name)
class ActiveRecord::Reflection::AssociationReflection
def derive_class_name
cn = ""
parent = active_record.parent
unless parent == Object
cn << "#{parent.name}::"
end
cn << name.to_s.camelize
cn = cn.singularize if collection?
cn
@kaorukobo
kaorukobo / less-diskseek.diff
Created May 15, 2011 01:46
Reduce/less disk seek patch for daemontools-0.76 ( delays the scanning interval to 15sec (default is 5sec) - can change with 'export SVSCAN_INTERVAL_SEC=nnn'), suitable for developer's machine!)
Index: daemontools-0.76/src/supervise.c
===================================================================
RCS file: /home/shirai/root/cvs/project/other/daemontools/daemontools-0.76/src/supervise.c,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -r1.1.1.1 -r1.4
--- daemontools-0.76/src/supervise.c 16 Dec 2001 02:54:52 -0000 1.1.1.1
+++ daemontools-0.76/src/supervise.c 30 May 2002 07:33:07 -0000 1.4
@@ -15,6 +15,10 @@
#include "iopause.h"