Skip to content

Instantly share code, notes, and snippets.

@masiuchi
masiuchi / jquery.click.select.js
Last active September 29, 2015 02:32
Select text when clicking.
// http://stackoverflow.com/questions/4165010/use-jquery-to-auto-select-text-inside-a-span-tag-when-clicked
(function($) {
$.fn.clickSelect = function() {
this.click(function() {
var range = document.createRange();
range.setStartBefore(this.firstChild);
range.setEndAfter(this.lastChild);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
@masiuchi
masiuchi / Vagrantfile
Last active November 22, 2015 12:58
Vagrantfile for building Docker environment on Ubuntu 14.04 LTS.
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
$script = <<SCRIPT
apt-get update
# Docker
# http://www.atmarkit.co.jp/ait/articles/1406/10/news031.html
@masiuchi
masiuchi / middleware.go
Last active April 16, 2016 10:57
Go sample code of net/http middleware.
package main
// http://www.alexedwards.net/blog/making-and-using-middleware
import (
"errors"
"fmt"
"html"
"log"
"net/http"
@masiuchi
masiuchi / .travis.yml
Created May 4, 2016 02:33
Use multiple languages in a build on Travis CI.
matrix:
include:
- language: perl
perl: "5.16"
- language: php
php: "5.4"
@masiuchi
masiuchi / app.rb
Created May 20, 2016 04:00
Sinatra application sample for checking JavaScript behaviour.
require 'sinatra'
get '/' do
<<'HTML'
<html>
<head>
<script src="js-alert"></script>
<script src="html-alert"></script>
<script src="js-script"></script>
<script src="html-script"></script>
@masiuchi
masiuchi / language.html
Created May 26, 2016 09:55
Display language information of the browser.
<html>
<body>
<div id="language">window.navigator.language: </div>
<div id="languages">window.navigator.languages: </div>
<div id="user-language">window.navigator.userLanguage: </div>
<div id="browser-language">window.navigator.browserLanguage: </div>
</body>
<script>
var language = document.getElementById('language');
@masiuchi
masiuchi / provision.sh
Last active December 12, 2022 15:07
Install Docker and Docker Compose to Ubuntu 14.04 LTS.
#!/bin/bash
# https://docs.docker.com/engine/installation/linux/ubuntulinux/
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo bash -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list'
sudo apt-get update
sudo apt-get -y install linux-image-extra-$(uname -r)
sudo apt-get -y install docker-engine
@masiuchi
masiuchi / pre-push
Last active June 18, 2017 09:30
Forbit pushing in off time.
#!/usr/bin/env ruby
# -*- mode:ruby; coding:utf-8 -*-
require 'date'
require 'off_time_jp' # https://github.com/masiuchi/off_time_jp
if OffTimeJp.off_time?
puts 'Forbid pushing in off time'
exit false
end
@masiuchi
masiuchi / update_all_vagrant_boxes.sh
Created November 6, 2017 02:30
Update all Vagrant boxes
vagrant box list | cut -d' ' -f1 | xargs -I {} vagrant box update --box {}
@masiuchi
masiuchi / mt-dev.sh
Created November 14, 2017 02:15
Run MT for development
start_server --port=5000 --pid-file=mt.pid -- plackup -r -R ./plugins -s Starman mt.psgi