Skip to content

Instantly share code, notes, and snippets.

@Sankame
Sankame / SampleTest.php
Created May 6, 2020
Sample code using Laravel, PHPUnit and Mockery
View SampleTest.php
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testEditWhenRecordNotFound()
{
$this->mock = M::mock('alias:App\Contact')->makePartial();
$this->mock->shouldReceive('find')->once()->with(self::ID)->andReturnUsing(function(){
return null;
@Sankame
Sankame / SampleTest.php
Last active May 6, 2020
Sample code using Laravel, PHPUnit and Mockery
View SampleTest.php
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testEditNormal()
{
$this->mock = M::mock('alias:App\Contact')->makePartial();
$this->mock->shouldReceive('find')->once()->with(self::ID)->andReturnUsing(function(){
$contacts = (object)array(
@Sankame
Sankame / Sample.php
Created May 6, 2020
Sample code using Laravel, PHPUnit and Mockery
View Sample.php
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$contact = Contact::find($id);
@Sankame
Sankame / KanaSample.html
Last active Sep 22, 2019
A sample code to change the half-sized kana to full-sized one in Japanese
View KanaSample.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
</head>
<body>
<script>
function Kana(){
View SampleActivity.java
File file = ...
// (1)
// intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
// (2)
Uri uri = FileProvider.getUriForFile(
【アクティビティ名】.this
,getApplicationContext().getPackageName() + ".provider"
, file);
View provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<application ...>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
@Sankame
Sankame / HttpPostSuccess.java
Last active May 9, 2018
サーバーからのレスポンスが多くてもOK
View HttpPostSuccess.java
public JSONObject post(String urlString) throws Exception{
URL url = new URL(urlString);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setConnectTimeout(Const.HTTP_CONNECT_TIMEOUT);
con.setReadTimeout(Const.HTTP_READ_TIMEOUT);
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setChunkedStreamingMode(0);
@Sankame
Sankame / HttpPostFailure.java
Last active May 9, 2018
サーバーからのレスポンスデータが多いとエラーになる
View HttpPostFailure.java
public JSONObject post(String urlString) throws Exception{
URL url = new URL(urlString);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setConnectTimeout(Const.HTTP_CONNECT_TIMEOUT);
con.setReadTimeout(Const.HTTP_READ_TIMEOUT);
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setChunkedStreamingMode(0);
@Sankame
Sankame / enable_vbs.reg
Created Jan 19, 2018
グループポリシーのvbscript設定を有効にする
View enable_vbs.reg
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3]
"140C"=dword:00000000