Skip to content

Instantly share code, notes, and snippets.

View naotaco's full-sized avatar
📷
Dreaming of going out for photography

Nao taco naotaco

📷
Dreaming of going out for photography
  • Japan
View GitHub Profile
@naotaco
naotaco / detect_orientation.cs
Created October 3, 2015 05:12
Detect current screen orientation on UWP application.
private void Page_Loaded(object sender, RoutedEventArgs e)
{
DisplayInformation.GetForCurrentView().OrientationChanged += MainPage_OrientationChanged;
}
private void MainPage_OrientationChanged(DisplayInformation info, object args)
{
Debug.WriteLine("orientation: " + info.CurrentOrientation);
}
@naotaco
naotaco / VisualStateSample.cs
Created August 16, 2015 16:46
A sample CS code for VisualState
private void Page_Loaded(object sender, RoutedEventArgs e)
{
InitializeVisualStates();
}
private void InitializeVisualStates()
{
var groups = VisualStateManager.GetVisualStateGroups(LayoutRoot);
groups[0].CurrentStateChanged += (sender, e) =>
{
@naotaco
naotaco / VisualStateSample.xaml
Last active October 3, 2015 07:00
A sample XAML code for VisualState
<Page
...
Loaded="Page_Loaded">
<Grid x:Name="LayoutRoot">
<Grid>
<Image x:Name="Image01" Source="your_source" />
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="WindowWidthStates">
#!/bin/bash
event=$1
device=$2
curl -s --data "[mdadm]: @naotaco $event $device" $'https://[slack id].slack.com/services/hooks/slackbot?token=[token]&channel=%23[channel]' >/dev/null
@naotaco
naotaco / cooker-front.conf
Created March 28, 2015 19:02
Conf file for supervisord to keep running cooker-frontapp
[program:front]
command=/etc/cooker/front/cooker-front.sh
process_name=%(program_name)s_%(process_num)02d
numprocs=1
autostart=false
autorestart=true
redirect_stderr=true
environment=GOROOT="/usr/bin/go",GOPATH="/home/user/go_path"
@naotaco
naotaco / setpoint.py
Created March 25, 2015 15:36
set target temperature to Redis
#!/usr/bin/python3
import redis
import sys
argvs = sys.argv
if (len(argvs) < 2):
print ("specify target temerature for first argument.")
sys.exit(1)
r = redis.Redis(host='127.0.0.1', port=6379, db=0)
@naotaco
naotaco / get-setpoint.py
Created March 25, 2015 15:35
reading setpoint from Redis DB
import redis
redis_db = redis.Redis(host='127.0.0.1', port=6379, db=0)
new_setpoint = 0.0
try:
new_setpoint = float(redis_db.get('cooker_target_temperature'))
except ValueError:
new_setpoint = 0.0
if (new_setpoint > 0 and new_setpoint != setpoint):
print ("setpoint updated from " + str(setpoint) + " to " + str(new_setpoint))
@naotaco
naotaco / cooker-exit.py
Created March 25, 2015 15:31
shutdown codes
def _on_exit():
print ("at exit")
turn_off()
time.sleep(1)
GPIO.cleanup()
print ("exit handler triggered")
time.sleep(1)
def on_exit(sig, func=None):
_on_exit()
@naotaco
naotaco / cooker.conf
Created March 25, 2015 15:25
conf file for supervisord
[program:cooker]
command=/etc/cooker/script/cooker-daemon.py
process_name=%(program_name)s_%(process_num)02d
numprocs=1
autostart=false
autorestart=true
redirect_stderr=true
@naotaco
naotaco / GPIO-test.py
Created March 12, 2015 15:41
GPIO-test
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import sys
import atexit
atexit.register(GPIO.cleanup)
pin = 35 # as board
GPIO.setmode(GPIO.BOARD)