Skip to content

Instantly share code, notes, and snippets.

@sleepless-se
sleepless-se / create_access_key_secret.py
Last active March 30, 2024 23:35
This script for create twitter ACCESS TOKEN KEY and ACCESS TOKEN SECRET.
import tweepy
import webbrowser
import urllib
CONSUMER_KEY = "*****"
CONSUMER_SECRET = "*****"
def get_oauth_token(url:str)->str:
querys = urllib.parse.urlparse(url).query
@sleepless-se
sleepless-se / Dockerfile
Created March 19, 2024 13:46
Selenium Python Docker Image
FROM python:3.12
# Install Chrome and Selenium dependencies
RUN apt-get update && apt-get install -y \
wget \
unzip \
libglib2.0-0 \
libnss3 \
libgconf-2-4 \
libfontconfig1 \
@sleepless-se
sleepless-se / image_to_byte_array.py
Created May 9, 2019 08:41
PIL image convert to byte array
from PIL import Image
import io
def image_to_byte_array(image:Image)
imgByteArr = io.BytesIO()
image.save(imgByteArr, format=image.format)
imgByteArr = imgByteArr.getvalue()
return imgByteArr
crontab -e
@sleepless-se
sleepless-se / coudbuild.yaml
Created May 20, 2022 14:20
How to set python test on cloudbuild.yaml
steps:
# Install modules
- name: 'python'
entrypoint: pip
args: [ "install", "-r", "requirements.txt", "--user" ]
# Run unit tests
- name: python
args: ["python","-m","unittest"]
id: unittest
@sleepless-se
sleepless-se / to_int_number.py
Created February 3, 2022 14:16
String number to int
@staticmethod
def to_int_number(text: str) -> int:
m = re.search(r'(\d+)', text)
if m is None: return 0
num = m.group()
return int(num)
@sleepless-se
sleepless-se / base.html
Created January 12, 2022 13:01
Footerを画面下に固定する
<body>
<div class="SiteWrapper">
<header>...</header>
<main>...</main>
<footer>...</footer>
</div>
</body>
<style>
.SiteWrapper {
display: flex;
@sleepless-se
sleepless-se / Utility.java
Last active November 11, 2021 12:21
How to get absolute file path in .jar file
public class Utility {
public static void main(String[] args) throws Exception {
Utility utility = new Utility();
String absolutePath = utility.getAbsolutePath("./credentials.json");
}
public String getAbsolutePath(String relativeFilePath) throws IOException {
URL url = this.getClass().getResource(relativeFilePath);
return url.getPath();
@sleepless-se
sleepless-se / Utility.java
Last active November 11, 2021 11:41
Google Authentification file read from .jar file.
public class Utility {
public static void main(String[] args) throws Exception {
Utility utility = new Utility();
GoogleCredentials credentials = utility.getGoogleCredentials("./credentials.json");
}
GoogleCredentials getGoogleCredentials(String jsonPath) throws IOException {
// You can specify a credential file by providing a path to GoogleCredentials.
// Otherwise credentials are read from the GOOGLE_APPLICATION_CREDENTIALS
@sleepless-se
sleepless-se / functions.php
Last active November 11, 2021 08:55
[textarea* yomigana] の日本語入力判定
```
// コンタクトフォーム7 日本語判定 ここから
add_filter('wpcf7_validate_textarea', 'wpcf7_validate_yomigana', 11, 2);
add_filter('wpcf7_validate_textarea*', 'wpcf7_validate_yomigana', 11, 2);
function wpcf7_validate_yomigana($result,$tag){
$tag = new WPCF7_Shortcode($tag);
$name = $tag->name;
$value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : "";
// 入力項目名が、'yomigana'の場合に実行
if ( $name === "yomigana") {