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 / 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)
@jugyo
jugyo / spec_helper.rb
Created May 7, 2012 15:36
spec_helper.rb for sinatra app to use capybara with selenium driver
ENV['APP_ENV'] = 'test'
require_relative '../app.rb'
disable :run
require 'capybara'
require 'capybara/dsl'
Capybara.app = Sinatra::Application
if ENV['TEST_BROWSER']
Capybara.register_driver :selenium do |app|
import android.database.Cursor
inline operator fun <reified T> Cursor.get(column: String): T? {
val columnIndex = getColumnIndex(column)
if (columnIndex == -1) {
// Column not found
return null
}
return when (T::class) {
@jugyo
jugyo / gist:3882497
Created October 13, 2012 00:16
nginx + ngx_lua on Mac
@jugyo
jugyo / gist:2992584
Created June 26, 2012 01:33
render_haml helper
module ApplicationHelper
# Usage:
#
# render_haml <<-HAML, foo: "FOO"
# %p Hello #{foo}!
# HAML
#
def render_haml(template, locals = {})
engine = Haml::Engine.new(template.gsub(/^#{template[/^\s+/]}/, ''))
engine.render(self, locals)
package com.example.compose_drag_and_drop
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectDragGesturesAfterLongPress
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
@jugyo
jugyo / gist:3423990
Created August 22, 2012 09:21
Using Google Translate API in Python
import urllib2
import json
url = 'https://www.googleapis.com/language/translate/v2?key={0}&q={1}&source={2}&target={3}'
def translate(api_key, text, sourcelang, targetlang):
request = urllib2.Request(url.format(api_key.encode('utf-8'), text.encode('utf-8'), sourcelang.encode('utf-8'), targetlang.encode('utf-8')))
response = urllib2.urlopen(request).read()
data = json.loads(response)
return data['data']['translations'][0]['translatedText'].encode('utf-8')
@jugyo
jugyo / nginx.conf
Created September 27, 2012 09:02
nginx.conf to switch proxy for mobile
http {
upstream app-pc {
server 127.0.0.1:8001;
}
upstream app-mobile {
server 127.0.0.1:8002;
}
server {
@jugyo
jugyo / full-text-search-by-groonga-and-ruby.md
Created August 15, 2012 07:35
Groonga + Ruby で全文検索

Groonga + Ruby で全文検索

groonga のインストール

$ brew install groonga

rroonga のインストール

Ruby から groonga を使うために rroonga というライブラリを使う:

import UIKit
class FloatingView: UIView {
var keyboardSize: CGFloat = 0
open var height: CGFloat = 56 {
didSet {
self.setNeedsDisplay()
}