Skip to content

Instantly share code, notes, and snippets.

View jugyo's full-sized avatar
🏠
Working from home

Kaz jugyo

🏠
Working from home
  • The League
  • New Jersey
View GitHub Profile
@jugyo
jugyo / abstract_mysql_adapter_patch_for_spatial_index.rb
Created December 7, 2017 22:41
A patch for Rails 5 to use MySQL spatial index
require "active_record/connection_adapters/abstract_mysql_adapter"
# NOTE: Set SRID 0 as same as mysql's default
silence_warnings do
GeoRuby::SimpleFeatures::DEFAULT_SRID = 0
end
module ActiveRecord
module Type
class Spatial < Value
@jugyo
jugyo / request_logger.rb
Last active November 16, 2023 17:25
Rack middleware for logging all rails request
# Add below into config/application.rb:
#
# config.middleware.use 'RequestLogger'
#
class RequestLogger
def initialize app
@app = app
end
def call(env)
import UIKit
class FloatingView: UIView {
var keyboardSize: CGFloat = 0
open var height: CGFloat = 56 {
didSet {
self.setNeedsDisplay()
}
@jugyo
jugyo / patch_for_dataset.rb
Created July 7, 2017 21:35
A patch to add a method Gogole::Cloud::Bigquery::Dataset#create_time_partitioned_table
module Google
module Cloud
module Bigquery
class Dataset
def create_time_partitioned_table table_id, name: nil, description: nil, type: 'DAY', expiration_ms: nil
ensure_service!
new_tb = Google::Apis::BigqueryV2::Table.new(
table_reference: Google::Apis::BigqueryV2::TableReference.new(
project_id: project_id, dataset_id: dataset_id,
table_id: table_id),
@jugyo
jugyo / mysql2spatial.rb
Created October 26, 2016 14:12
A patch for spatial data support for rails's mysql2 adapter, only support `point` geometry data
require 'geo_ruby/ewk'
# NOTE: Set SRID 0 as same as mysql's default
GeoRuby::SimpleFeatures::DEFAULT_SRID = 0
module ActiveRecord
module Type
class Spatial < Value
def type
:spatial
import Foundation
import UIKit
extension UITableView {
// NOTE: Workaround for the broblem of iOS8 when using UITableViewAutomatic Dimension. http://stackoverflow.com/questions/25589540/uitableview-refresh-without-scrolling
func reloadDataWithKeepingContentOffset() {
let prevContentOffset = contentOffset
reloadData()
layoutIfNeeded()
contentOffset = prevContentOffset
class func setupRealm() {
let config = Realm.Configuration(
deleteRealmIfMigrationNeeded: true
)
Realm.Configuration.defaultConfiguration = config
// Test
do {
try Realm()
} catch let error as NSError {
@jugyo
jugyo / build.gradle
Created March 13, 2014 01:49
Example of using com.twitter.Extractor with gradle
buildscript {
repositories {
// mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.twitter:twitter-text:1.9.0'
}
}
@jugyo
jugyo / get_tlds.rb
Created March 10, 2014 07:17
Script to get TLDs from iana.org
require 'open-uri'
require 'nokogiri'
doc = Nokogiri::HTML(open('http://www.iana.org/domains/root/db'))
tlds = []
doc.css('table#tld-table tr').each do |tr|
info = tr.css('td')
next if info.empty?
tlds << {
@jugyo
jugyo / build.gradle
Last active August 29, 2015 13:56 — forked from seratch/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.twitter4j', name: 'twitter4j-core', version: '3.0.5'
}
}
import twitter4j.*