Skip to content

Instantly share code, notes, and snippets.

View gothedistance's full-sized avatar
Let's go swallows

YUMOTO Michitaka gothedistance

Let's go swallows
View GitHub Profile
@gothedistance
gothedistance / mysql2sqlite.sh
Last active December 14, 2015 16:28 — forked from esperlu/mysql2sqlite.sh
Mysql Comment not support in sqlite3. added erase comments on line 75.
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@gothedistance
gothedistance / gist:5243455
Last active October 14, 2022 22:59
Sessionに格納する値が連想配列とオブジェクトのどっちがいいかという話
Dictionary<string,string> dict = new Dictionary<string,string>();
dict.add("name","POSTされた値");
dict.add("address","POSTされた値");
.
.
.
Session["data"] = dict;
//これを取り出す時にはこうなる
@gothedistance
gothedistance / gist:5243840
Created March 26, 2013 08:17
こんな感じですよ、クラスの実装って。
public class UserData
{
public string Id { set; get; }
public string Username { set; get; }
public string Password { set; get; }
public string Name { set; get; }
public string Kana { set; get; }
public string Tel { set; get; }
public string MailAddress { set; get; }
public string UserRole { set; get; }
UPDATE movie_log
INNER JOIN (
SELECT
item_id,
date,
view +
(
comment *
(
@gothedistance
gothedistance / Using bindModel to get to deep relations
Last active December 19, 2015 09:19
CakePHPで深いJoinが必要な場合は、Containableを使うよりも確実に以下のTipsに従ったほうがいい。確実でしかもSQLもシンプルになり、早い。 Via http://mark-story.com/posts/view/using-bindmodel-to-get-to-deep-relations
CakePHP Behaviouer 'Containable' is very useful,but it's not suitable plugin for fetch deep join records.
I want to join 4 Tables as such.
OrderEntryDetail->Item->Maker->Category
Containable runs sql for each model(equivalent each table) but this tricky BindModel/UnBindModel usage solves this problem.
<Before>
<?php
@gothedistance
gothedistance / calc_jancode_digit.php
Last active August 29, 2015 13:56
JANコードのチェックデジットを計算するPHPコード
<?php
function calcJanCodeDigit($num) {
$arr = str_split($num);
$odd = 0;
$mod = 0;
for($i=0;$i<count($arr);$i++){
if(($i+1) % 2 == 0) {
//偶数の総和
$mod += intval($arr[$i]);
} else {
<?php
function renameForWelcartImage ( $path ) {
if (is_dir($path) === false) {
echo 'not directory path';
exit();
}
$file = scandir($path);
$count = 0;
foreach($file as $key){
if ('.' == $key || '..' == $key) { continue; }
@gothedistance
gothedistance / invoice.xaml
Last active August 29, 2015 14:04
納品書ユーザーコントロール
<UserControl x:Class="Sample.Invoice"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="1100" d:DesignWidth="800">
<Grid Background="White" Margin="20" DataContext="{StaticResource VMContainer}">
<Grid.RowDefinitions>
<!-- Title-->
@gothedistance
gothedistance / api.py
Last active August 29, 2015 14:12 — forked from alanhamlett/api.py
import uuid
import wtforms_json
from sqlalchemy import not_
from sqlalchemy.dialects.postgresql import UUID
from wtforms import Form
from wtforms.fields import FormField, FieldList
from wtforms.validators import Length
from flask import current_app as app
from flask import request, json, jsonify, abort
@gothedistance
gothedistance / postgre_join_condition.sql
Created September 11, 2015 15:05
PostgreはJOIN句に式を書ける
select
c.customer_id,
c.customer_age,
c.customer_name,
ca.name,
ca.rank
from
customers as c
inner join customer_category as ca
on (c.customer_age /5 *5) = ca.rank