Skip to content

Instantly share code, notes, and snippets.

@hitsujixgit
hitsujixgit / functions.php
Created February 6, 2015 13:12
How to accept svg image files on your wordpress theme.
<?php
// SVGファイルに対応する
add_filter( 'upload_mimes', 'my_add_mime_type' );
if( !function_exists('my_add_mime_type') ) {
function my_add_mime_type($mime_types)
{
$mime_types['svg'] = 'image/svg+xml';
$mime_types['svgz'] = 'image/svg+xml';
return $mime_types;
}
@hitsujixgit
hitsujixgit / main.coffee
Last active August 29, 2015 14:14
横浜市の地図を、人口に応じて色分け表示する
'use strict'
###
* 色を変換する関数を定義する
###
hex2rgb = (hexcode) ->
# rgbに変換する
result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexcode);
if result is null
console.log "error!"
@hitsujixgit
hitsujixgit / hex2rgb.coffee
Created January 22, 2015 01:52
Convert color systems
hex2rgb = (hexcode) ->
# rgbに変換する
result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexcode);
if result is null
console.log "error!"
return
[r,g,b] = [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)]
return [r,g,b]
@hitsujixgit
hitsujixgit / lawson.coffee
Created January 12, 2015 04:25
CasperJS crawler sample.
###
* ローソンの店舗情報を1件スクレイピングする
###
target_url = "http://store.lawson.co.jp"
casper = require('casper').create()
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36')
casper.start target_url
# 都道府県リスト表示
@hitsujixgit
hitsujixgit / get_captures.coffee
Last active August 29, 2015 14:13
Get captures on a list using CasperJS. (iPhone 6)
links = [
'http://google.co.jp/'
'http://yahoo.co.jp/'
'http://bing.com/'
]
casper = require('casper').create()
# iPhone 6
casper.userAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4')
@hitsujixgit
hitsujixgit / forms.py
Created October 2, 2014 13:45
Add class attributes to option tags of select menu on Django projects.
# -*- coding: utf-8 -*-
from django import forms
from myapp.models import DataGroup # Overwrite this to your model
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
from django.utils.html import format_html
class DataGroupSelect(forms.widgets.Select):
def render_option(self, selected_choices, option_value, option_label):
@hitsujixgit
hitsujixgit / functions.php
Last active August 29, 2015 14:05
According to widget title, replace its string to image in WordPress.
<?php
// Widgetタイトルを画像に置き換える(タイトル検知版)
if( !function_exists('change_widget_title_to_image') ) {
function change_widget_title_to_image($params) {
// widget-idを、widget名と数字に分ける
if(preg_match('/^(?<name>.+)\-(?<key>\d+)$/', $params[0]['widget_id'], $m)) {
$option_name = 'widget_' . $m['name'];
$widgets = get_option($option_name, array());
$index = intval($m['key']);
@hitsujixgit
hitsujixgit / functions.php
Last active August 29, 2015 14:05
Replace WP widget title string to image.
<?php
// Widgetタイトルを画像に置き換える
if( !function_exists('change_widget_title_to_image') ) {
function change_widget_title_to_image($params) {
// categories-xxの形式で、画像を挿入する
if(preg_match('/^categories-\d+/', $params[0]['widget_id'])) {
$params[0]['before_title'] = $params[0]['before_title'].'<img src="'.get_bloginfo('template_url').'/img/categories_2x.png" width="91" height="20" alt="categories" /><span style="display:none;">';
$params[0]['after_title'] = '</span>'.$params[0]['after_title'];
} else if ( preg_match('/^recent-posts-\d+/', $params[0]['widget_id']) ) {
// recent-posts-xxの形式で、画像を挿入する
@hitsujixgit
hitsujixgit / mylineheight.js
Last active August 29, 2015 14:05
Adjusting line height according to window width.
$(function($) {
// 投稿用スクリプト. 見出しにぬこクラス追加
$(".post-content h3").addClass("cat-header1").wrapInner("<span></span>");
// 行数カウントして、ライン幅を補正する
function main() {
// ぬこクラス
$("div.post-content .cat-header1 span").css("line-height", "1em");
$('div.post-content .cat-header1 span').each(function(index) {
var header_height = $(this)[0].offsetHeight;
@hitsujixgit
hitsujixgit / functions.php
Created August 21, 2014 04:14
Setting of javascript in WordPress theme.
// javascript
add_action('wp_head', 'myJavaScript_head', 1);
if( !function_exists('myJavaScript_head') ) {
function myJavaScript_head() {
wp_deregister_script('jquery');
wp_register_script('jquery',get_bloginfo('template_url'). '/js/jquery-1.7.1.min.js');
wp_enqueue_script('jquery');
wp_enqueue_script('pageslide', get_bloginfo('template_url'). '/js/jquery.pageslide.min.js', array('jquery'), false, true);
wp_enqueue_script('mypageslide', get_bloginfo('template_url'). '/js/myPageslide.js', array('jquery'), false ,true);