Skip to content

Instantly share code, notes, and snippets.

@Restoration
Restoration / DatabaseHelper.java
Last active June 29, 2018 06:39
ToDo App Database Code
package com.example.bboyryu.myapplication;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
@Restoration
Restoration / transaction.java
Created June 25, 2018 04:30
Android DB transaction
// トランザクション開始
db.beginTransaction();
try {
/** Insert等のDB操作 */
db.setTransactionSuccessful();
} catch(Exception e) {
e.printStackTrace();
}
finally {
scriptencoding utf-8
"Basic Setting
"-----------------------------------------------------
set shortmess+=I
set number
set mouse=a
set ambiwidth=double
set tabstop=4
@Restoration
Restoration / controller.php
Created June 22, 2018 07:19
Laravelのかてごりー
//$category = Category::get();
//return view('article.edit', ['article' =>
$article,'categories'=>$category])->withErrors($validator)->withInput();
//$request->session()->flash();
//return
redirect('/article/create')->withErrors($validator)->withInput();
//return redirect()->route('article',
$article)->withErrors($validator)->withInput();
//return redirect()->action('ArticleController@create',
['articles' => $article])->withErrors($validator)->withInput();
@Restoration
Restoration / tips.md
Last active June 2, 2018 19:09
SQLSTATE[42000] : Specified key was too long error at migrate command

Error

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email))

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Solution

  • Update to newerst MySQL version
  • Change charaset from utf8mb4
@Restoration
Restoration / index.html
Created June 2, 2018 07:00
IEで見るとハローワークに飛ばすスクリプト
<script type="text/javascript">
var userAgent = window.navigator.userAgent.toLowerCase();
if(userAgent.indexOf('msie') != -1 || userAgent.indexOf('trident') != -1 ){
alert("IE嫌いなんだよ。");
location.href = "https://www.hellowork.go.jp";
}
</script>
@Restoration
Restoration / category_count.php
Created July 2, 2017 15:53
カスタムポストタイプの記事数を取得
<?php
$post_count = wp_count_posts('video')->publish;//publishを指定することで公開記事分だけ取れる
@Restoration
Restoration / query_post_pager_paged.md
Created July 2, 2017 15:53
query_post_pager_paged

クエリポストでページングをしたい場合 現在ページの指定がないと2ページ目だろうがなんだろうが1ページ目を読み込んでしまう そのためpagedで現在ページを指定する必要がある

<?php $paged = get_query_var('paged'); ?>
<?php query_posts("posts_per_page=10&paged=$paged"); ?>
@Restoration
Restoration / function.php
Created July 2, 2017 15:51
WordPressの管理画面の『表示設定』で 「1ページに表示する最大投稿数 」の値を取得する
<?php
get_option('posts_per_page');
@Restoration
Restoration / functions.php
Created June 30, 2017 12:33
WordPress remove support
<?php
/**
* 投稿画面から不要な機能を削除します。
*/
function remove_post_supports() {
remove_post_type_support( 'post', 'title' ); // タイトル
remove_post_type_support( 'post', 'editor' ); // 本文欄
remove_post_type_support( 'post', 'author' ); // 作成者
remove_post_type_support( 'post', 'thumbnail' ); // アイキャッチ
remove_post_type_support( 'post', 'excerpt' ); // 抜粋