Skip to content

Instantly share code, notes, and snippets.

@chimame
chimame / twilio_base_controller.rb
Created January 27, 2015 03:25
Twilio Request Validation for Rails
class TwilioBaseController < ActionController::Base
before_filter :authenticate_twilio_request
private
def authenticate_twilio_request
twilio_sig = request.headers['HTTP_X_TWILIO_SIGNATURE']
render :xml => (Twilio::TwiML::Response.new {|r| r.Hangup}).text and return if twilio_sig.blank?
twilio_validator = Twilio::Util::RequestValidator.new("YOUR TWILIO AUTH TOKEN")
params_for_auth = (request.post? ? env['rack.request.form_hash'] : {})
@chimame
chimame / datetime_integratable.rb
Last active August 29, 2015 14:27
datetime integratable for ActiveRecord
module DatetimeIntegratable
extend ActiveSupport::Concern
included do
after_initialize :initialize_integrate_datetime
def initialize_integrate_datetime
self.class.datetime_integrate_targets.each do |attribute|
decompose_datetime(attribute)
end
@chimame
chimame / MarqueeMessage.jsx
Last active August 18, 2016 07:08
marquee of react
import React, { Component } from 'react'
import $ from 'jquery'
import nl2br from 'react-nl2br'
export default class MarueeMessage extends Component {
autoScrollStart() {
$("div.maruee").css('position', 'relative')
let text_height = $("div.maruee p#first").height()
if (text_height > $("div.display-area").height()) {
if (!$('div.maruee').is(':animated')) {
@chimame
chimame / json
Created May 3, 2017 14:19
visual studio code setting
// 既定の設定を上書きするには、このファイル内に設定を挿入します
{
"editor.tabSize": 2,
"editor.renderWhitespace": "boundary",
"workbench.colorTheme": "Material Theme",
"workbench.iconTheme": "vscode-icons",
"workbench.editor.enablePreviewFromQuickOpen": false,
"window.zoomLevel": 1,
"window.newWindowDimensions": "maximized"
}
@chimame
chimame / chromedriver-updator.sh
Created June 4, 2017 13:55 — forked from yatt/chromedriver-updator.sh
chromedriverの自動更新スクリプト
#! /bin/bash
cd $(dirname $0)
# 現在パスが通っているchromedriverのバージョンと、chromedriverで公開されている
# 最新のchromedriverのバージョンを比較し、新しくなっている場合は更新する。
# chromedriverの保存先
CURRENT_CHROMEDRIVER=/home/user/bin/chromedriver
CHROMEDRIVER_ARCHIVE_DIR=/home/user/bin/selenium-webdriver/chromedriver/
'use strict'
const aws = require('aws-sdk')
const LineStream = require('byline').LineStream
const client = require('cheerio-httpcli')
const s3 = new aws.S3({ apiVersion: '2006-03-01' })
const ls = new LineStream()
exports.handler = (event, context, callback) => {
@chimame
chimame / export_assets_from_container.sh
Last active June 27, 2018 07:58
Dockerコンテナ内のassets系をキャッシュするために出力する処理
#!/bin/sh
IFS=$','
CACHE_DIRS="public/assets,tmp/cache"
WORK_DIR_IN_DOCKER="/app"
i=1
docker run -it -d --entrypoint /bin/sh --name run_cache_container <image name> -c /bin/sh
@chimame
chimame / install.md
Created January 23, 2024 01:46
How to install docker using colima on Mac
  1. Install docker and docker compose
brew install docker docker-compose
  1. Configure the docker plugin to recognize it as the docker compose command.
mkdir -p ~/.docker/cli-plugins
@chimame
chimame / context.ts
Created March 17, 2024 11:53
Automatic rollback of vitest using drizzle
import { Client } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from "../drizzle/schema";
import { Logger } from "drizzle-orm/logger";
export async function createContext() {
const client = new Client({
connectionString: "your database connection string",
});
await client.connect();