Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
😐

Kaz jugyo

💭
😐
  • MUA inc.
  • New York
View GitHub Profile
@jugyo
jugyo / gist:2992584
Created Jun 26, 2012
render_haml helper
View gist:2992584
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)
@jugyo
jugyo / request_logger.rb
Last active Sep 22, 2022
Rack middleware for logging all rails request
View request_logger.rb
# Add below into config/application.rb:
#
# config.middleware.use 'RequestLogger'
#
class RequestLogger
def initialize app
@app = app
end
def call(env)
View DraggableGridExample.kt
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 Aug 22, 2012
Using Google Translate API in Python
View gist:3423990
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 Sep 27, 2012
nginx.conf to switch proxy for mobile
View nginx.conf
http {
upstream app-pc {
server 127.0.0.1:8001;
}
upstream app-mobile {
server 127.0.0.1:8002;
}
server {
View full-text-search-by-groonga-and-ruby.md

Groonga + Ruby で全文検索

groonga のインストール

$ brew install groonga

rroonga のインストール

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

View FloatingView.swift
import UIKit
class FloatingView: UIView {
var keyboardSize: CGFloat = 0
open var height: CGFloat = 56 {
didSet {
self.setNeedsDisplay()
}
@jugyo
jugyo / index.js
Last active Nov 26, 2020
An example to send email with Cloud Pub Sub and Cloud Functions #Rails
View index.js
const sendEmail = require('./sendEmail').sendEmail;
/**
* Deplooyment:
*
* $ gcloud beta functions deploy sendEmail --trigger-topic sendEmail
*
*/
/**
@jugyo
jugyo / file_name_on_status_bar.py
Created Feb 26, 2013
Sublime Text Plugin to show file name on status bar
View file_name_on_status_bar.py
import sublime_plugin
class FileNameOnStatusBar(sublime_plugin.EventListener):
def on_activated(self, view):
path = view.file_name()
if path:
for folder in view.window().folders():
path = path.replace(folder + '/', '', 1)
view.set_status('file_name', path)
else:
@jugyo
jugyo / sublime_text_2_plugin_tips.md
Created Aug 13, 2012
Sublime Text 2 Plugin Tips
View sublime_text_2_plugin_tips.md

Sublime Text 2 Plugin Tips

API Reference

コマンドの実行はコンソール( ctrl + ` で開ける)で以下を実行する:

view.run_command('example')