Instantly share code, notes, and snippets.

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)
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, {
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>
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);
}
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.

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
View python_test_sample_with_mocks.py
import unittest
from unittest import mock
import requests
import PypiPackageInfo
URL_JSON = ...
View compress_dir_exluding_ds_store.py
# 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
View chmod.py
# coding: utf-8
'''Provides functions to add file permissions.
'''
import stat
from pathlib import Path
from functools import reduce
# read:
View fibonacci_with_linear_order.py
# coding: utf-8
"""Gets Fibonacci numbers with a linear Order.
"""
def get_fibonacci(n):
a = 0
b = 1
for i in range(0, n):