Skip to content

Instantly share code, notes, and snippets.

View gh640's full-sized avatar

Goto Hayato gh640

View GitHub Profile
@gh640
gh640 / sample-chart_js-click_event_handling_with_stacked_bar_chart.html
Last active November 16, 2018 04:35
Chart.js sample: Click event handling with stacked bars
<html>
<head>
<style>
.canvas-wrapper {
width: 600px;
margin: auto;
height: 600px;
}
</style>
</head>
@gh640
gh640 / ceil_floor_with_precision.php
Last active December 19, 2020 20:19
PHP: ceil() and floor() with precision
<?php
function ceil_plus(float $value, ?int $precision = null): float
{
if (null === $precision) {
return (float) ceil($value);
}
if ($precision < 0) {
throw new \RuntimeException('Invalid precision');
}
@gh640
gh640 / all_constants_defined_in_drupal_7_core.md
Last active July 13, 2018 07:52
All the constants defined in Drupal 7 core

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 July 6, 2018 08:42
Fabric コマンドサンプル
'''デプロイ関連タスクのための 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 July 6, 2018 11:56
Python でモックを使ったテストのサンプル
import unittest
from unittest import mock
import requests
import PypiPackageInfo
URL_JSON = ...
@gh640
gh640 / compress_dir_exluding_ds_store.py
Created December 16, 2017 13:04
A script to compresse a directory into a zip file excluding .DS_Store files in MacOS.
# coding: utf-8
'''Compresses a directory into a zip file excluding .DS_Store files in MacOS.
'''
import argparse
import zipfile
from pathlib import Path
from typing import Iterable, List
@gh640
gh640 / chmod.py
Last active May 25, 2019 13:23
Functions to add file permissions with Python.
# coding: utf-8
"""Provides functions to add file permissions.
read:
stat.S_IRUSR
stat.S_IRGRP
stat.S_IROTH
write:
@gh640
gh640 / fibonacci_with_linear_order.py
Created September 3, 2017 04:58
Get a Fibonacci number with O(n).
# coding: utf-8
"""Gets Fibonacci numbers with a linear Order.
"""
def get_fibonacci(n):
a = 0
b = 1
for i in range(0, n):
@gh640
gh640 / fibonacci_with_log_order.py
Created August 31, 2017 13:26
Get a Fibonacci number with O(log(n)).
# coding: utf-8
"""Get a Fibonacci number with O(log(n)).
1, 1, 2, 3, 5, 8, 13, 21, ...
The logic to get a Figonacci number with O(log(n)) is explained at https://kukuruku.co/post/the-nth-fibonacci-number-in-olog-n .
"""
from functools import lru_cache, reduce
@gh640
gh640 / tower_of_hanoi.py
Last active August 27, 2017 07:03
Tower of Hanoi with Python.
# coding: utf-8
"""Tower of Hanoi.
"""
TOTAL_DISK = 3
def main():
print('started.')