Skip to content

Instantly share code, notes, and snippets.

GOTO Hayato gh640

Block or report user

Report or block gh640

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gh640
gh640 / settings.py
Created Jul 2, 2019
Allow Django Debug Toolbar to be displayed when the app is running in a Docker container
View settings.py
"""Allow Django Debug Toolbar to be displayed when the app runs in a Docker container
See: https://gist.github.com/douglasmiranda/9de51aaba14543851ca3
"""
import socket
INTERNAL_IPS = ['127.0.0.1', '10.0.2.2']
@gh640
gh640 / form-reset-button.js
Created Apr 18, 2019
フォームのリセットボタンにフィールドの入力値をクリアする挙動を追加するスクリプト
View form-reset-button.js
(function (){
'use strict';
init();
/**
* ページ読み込み時処理
*/
function init() {
addClearBehavior();
@gh640
gh640 / hello.py
Created Mar 18, 2019
Minimal Django project for django 2.1.x
View hello.py
"""Minimal Django project for django 2.1.x.
This code is mostly borrowed from http://shop.oreilly.com/product/0636920032502.do .
"""
import sys
from django.conf import settings
from django.http import HttpResponse
from django.urls import path
@gh640
gh640 / pandas_stack_column.py
Created Dec 8, 2018
Python Pandas: Stack a column in a DataFrame
View pandas_stack_column.py
import pandas as pd
def stack_with_column(df, column, sep=','):
"""Stack a column splitting with `sep` in a DataFrame.
"""
stacked_column = (
df[column].str.split(sep, expand=True)
.stack()
.reset_index(1, drop=True)
@gh640
gh640 / sample-chart_js-lined_scatter_chart.html
Created Dec 1, 2018
Chart.js sample: Scatter chart with straight lines
View sample-chart_js-lined_scatter_chart.html
<!DOCTYPE>
<html>
<body>
<canvas id="canvas"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>
<script>
// see: https://www.chartjs.org/docs/latest/charts/scatter.html
// see: https://stackoverflow.com/questions/46232699/display-line-chart-with-connected-dots-using-chartjs
const ctx = document.querySelector('#canvas');
const scatterChart = new Chart(ctx, {
@gh640
gh640 / sample-chart_js-click_event_handling_with_stacked_bar_chart.html
Last active Nov 16, 2018
Chart.js sample: Click event handling with stacked bars
View sample-chart_js-click_event_handling_with_stacked_bar_chart.html
<html>
<head>
<style>
.canvas-wrapper {
width: 600px;
margin: auto;
height: 600px;
}
</style>
</head>
@gh640
gh640 / ceil_floor_with_precision.php
Created Oct 30, 2018
PHP: ceil() and floor() with precision
View ceil_floor_with_precision.php
<?php
function ceil_plus($value, $precision = 1) {
return round($value + 0.5 * pow(0.1, $precision), $precision, PHP_ROUND_HALF_DOWN);
}
function floor_plus($value, $precision = 1) {
return round($value - 0.5 * pow(0.1, $precision), $precision, PHP_ROUND_HALF_UP);
}
@gh640
gh640 / all_constants_defined_in_drupal_7_core.md
Last active Jul 13, 2018
All the constants defined in Drupal 7 core
View all_constants_defined_in_drupal_7_core.md

Base

define('DRUPAL_ROOT', getcwd());
define('VERSION', '7.60-dev');
define('DRUPAL_CORE_COMPATIBILITY', '7.x');

The value of VERSION (7.60-dev) above varies for each version.

@gh640
gh640 / fabric_sample.py
Created Jul 6, 2018
Fabric コマンドサンプル
View fabric_sample.py
'''デプロイ関連タスクのための Fabric コマンド'''
# .env ファイルの中身は次のとおり
# hosts=ホスト名A|ホスト名B
# shell='/usr/local/bin/bash -l -c'
# project_path='/var/www/プロジェクト名'
from functools import wraps
from pathlib import Path
@gh640
gh640 / python_test_sample_with_mocks.py
Last active Jul 6, 2018
Python でモックを使ったテストのサンプル
View python_test_sample_with_mocks.py
import unittest
from unittest import mock
import requests
import PypiPackageInfo
URL_JSON = ...
You can’t perform that action at this time.