Skip to content

Instantly share code, notes, and snippets.

Avatar

Toshihiko Arai araemon

View GitHub Profile
View led_switch_client.html
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js">
</script>
<script>
$(function () {
var ws = new WebSocket("ws://192.168.100.136:5555/");
$('#btn').on('click', function () {
View led_switch_sever.py
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
from time import sleep
from websocket_server import WebsocketServer
LED = 11
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED, GPIO.OUT)
@araemon
araemon / blink_led_5_times_rpi_gpio.py
Created Nov 24, 2020
ラズパイでLEDを5回点滅させるプログラム(RPI.GPIO) -> https://101010.fun/iot/raspberry-pi-webbrowser-remote.html
View blink_led_5_times_rpi_gpio.py
@araemon
araemon / bmx055.py
Created Nov 22, 2020
BOSCHのBMX055を使ってラズパイでジャイロと加速度の値を読み取るPythonプログラム -> https://101010.fun/iot/raspberry-pi-gyro-bmx055.html
View bmx055.py
# -*- coding: utf-8 -*-
import smbus
import time
ACCL_ADDR = 0x19
GYRO_ADDR = 0x69
bus = smbus.SMBus(1)
@araemon
araemon / ScrapingSiteTitle.py
Created Nov 21, 2020
Pythonでサイトタイトルを抽出(スクレイピング)するプログラム/https://101010.fun/programming/python-beautifulsoup-googlerank.html
View ScrapingSiteTitle.py
import urllib.request
from bs4 import BeautifulSoup
url = "https://101010.fun/posts/world-ios-android-share-2020.html"
req = urllib.request.Request(url)
with urllib.request.urlopen(req) as res:
html = res.read()
@araemon
araemon / controllViews.swift
Last active Oct 28, 2020
【Swift】同じクラスタイプのViewを一括で操作する >>> https://101010.fun/programming/swift-memo.html
View controllViews.swift
for v in view.subviews {
if v.isKind(of: UISegmentedControl.self) {
let sc = v as! UISegmentedControl
if #available(iOS 13.0, *) {
sc.selectedSegmentTintColor = .pink
} else {
// Fallback on earlier versions
}
sc.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .normal)
sc.backgroundColor = .black
@araemon
araemon / buttonTint.swift
Last active Oct 28, 2020
【Swift】UIImageViewやUIButtonの色を、tintColorで変えられるようにする>>> https://101010.fun/programming/swift-memo.html
View buttonTint.swift
let image = UIImage(named: "hoge")?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
button.setImage(image, for: .normal)
button.tintColor = .red
@araemon
araemon / barStyle.swift
Last active Oct 28, 2020
【Swift】ナビゲーションバーの色を変える >>> https://101010.fun/programming/swift-memo.html
View barStyle.swift
// ナビゲーションバーのタイトル
self.navigationItem.title = "ランキング"
// ナビゲーションバーのタイトル色
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
// ナビゲーションバーの背景色
self.navigationController?.navigationBar.barTintColor = .questionAreaBackground
let closeItem = UIBarButtonItem(title: "x", style: .plain, target: self, action: #selector(closeWindow))
@araemon
araemon / cellBackground.swift
Last active Oct 28, 2020
【Swift】テーブルセルの背景色を変える >>> https://101010.fun/programming/swift-memo.html
View cellBackground.swift
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.backgroundColor = .black
}
View orientationDidChange.swift
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(orientationDidChange(_:)), name: UIDevice.orientationDidChangeNotification, object: nil)
}
var lastOrientation: UIDeviceOrientation?
@objc func orientationDidChange(_ notification: NSNotification) {
let device = UIDevice.current
if device.orientation.isLandscape {
You can’t perform that action at this time.