Skip to content

Instantly share code, notes, and snippets.

View gh640's full-sized avatar

Goto Hayato gh640

View GitHub Profile
@gh640
gh640 / den.sh
Last active March 10, 2020 02:23
Deprecated bash functions/aliases on macOS
# Shortcut to download and install a Drupal project on Drupal 7
function den {
local module_name
if [[ "${1}" == *"https://www.drupal.org/project"* ]]; then
module_name=$(echo "${1}" | grep -Eo "[^\/]+$")
echo "$module_name is being installed..."
else
module_name="${1}"
fi
@gh640
gh640 / sudoku_solver.py
Last active February 29, 2020 06:46
サンプルコード: 数独パズルを Python で解く
"""数独を解く
- 無駄な探索の枝を事前に減らすために入る値の候補が少ないセルを先に埋める
- 動作検証環境:
- Python 3.7
- 参考:
- https://www.youtube.com/watch?v=G_UYXzGuqvM
"""
from __future__ import annotations
@gh640
gh640 / Dockerfile
Created January 4, 2020 14:36
Sample: Python Poetry installation in Docker container
FROM python:3.8
ENV POETRY_VERSION=1.0.0 \
PATH="/root/.poetry/bin:$PATH"
WORKDIR /app
RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/${POETRY_VERSION}/get-poetry.py | python && \
poetry config virtualenvs.create false
@gh640
gh640 / upload_mimes_hook.php
Created December 25, 2019 05:26
Makes it possible to upload svg files to media on WordPress.
<?php
add_filter('upload_mimes', 'myplugin_mime_types');
/**
* メディアでアップロード可能なメディアのタイプに svg を追加する
*
* @see https://developer.wordpress.org/reference/hooks/upload_mimes/
*/
function myplugin_mime_types( $mimes ) {
@gh640
gh640 / open_link_in_new_tab.js
Created December 12, 2019 11:23
A script to open links to external pages in new tabs
@gh640
gh640 / settings.py
Created July 2, 2019 01:46
Allow Django Debug Toolbar to be displayed when the app is running in a Docker container
"""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 April 18, 2019 06:13
フォームのリセットボタンにフィールドの入力値をクリアする挙動を追加するスクリプト
(function (){
'use strict';
init();
/**
* ページ読み込み時処理
*/
function init() {
addClearBehavior();
@gh640
gh640 / hello.py
Created March 18, 2019 03:35
Minimal Django project for django 2.1.x
"""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 December 8, 2018 11:53
Python Pandas: Stack a column in a DataFrame
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 December 1, 2018 14:16
Chart.js sample: Scatter chart with straight lines
<!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, {