This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
#define loopInterval 33 // loop関数のループ間隔[msec] | |
#define echoPin 2 // 超音波センサーからの入力ピン | |
#define trigPin 4 // 超音波センサーへのトリガ出力ピン | |
#define servoPin1 3 // 1つ目のサーボモーターを制御するピン | |
#define servoPin2 5 // 2つ目のサーボモーターを制御するピン | |
#define sonicSpeed 340 // 音速[m/sec] | |
#define sensorFilterLength 30 // 超音波センサー入力の平滑化フィルタの長さ | |
#define switchOnDistance 1.0 // サーボモータの角度をONに切り替える基準とする距離[cm] | |
#define switchOffDistance 6.0 // サーボモータの角度をOFFに切り替える基準とする距離[cm] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#region usage | |
function usage { | |
cat <<EOF | |
$(basename ${0}) by.もち: | |
ブログ投稿用に、画像・動画ファイルの一括リネームを行うスクリプト。 | |
引数で指定したディレクトリの直下にあるファイルのみが対象。 | |
各メディアファイルに対して次の処理を行う。 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
SampleUnion u = new SampleUnion { x = 0x01020304 }; | |
Console.WriteLine($"u = {u.x}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.InteropServices; | |
namespace ConsoleApp1 | |
{ | |
[StructLayout(LayoutKind.Explicit)] | |
struct SampleUnion | |
{ | |
[FieldOffset(0)] | |
public uint x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
union SampleUnion | |
{ | |
unsigned int x; | |
unsigned char byte[4]; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (Process currentProcess = Process.GetCurrentProcess ()) | |
using (ProcessModule currentModule = currentProcess.MainModule) { | |
// メソッドをマウスのイベントに紐づける。 | |
_mouseHookId = NativeMethods.SetWindowsHookEx ( | |
NativeMethods.HookType.WH_MOUSE_LL, | |
_mouseProc, | |
NativeMethods.GetModuleHandle (currentModule.ModuleName), | |
0 | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NativeMethods.UnhookWindowsHookEx(_mouseHookId); | |
NativeMethods.UnhookWindowsHookEx(_keyboardHookId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// デリゲート | |
private static readonly NativeMethods.LowLevelMouseKeyboardProc _mouseProc = MouseInputCallback; | |
private static readonly NativeMethods.LowLevelMouseKeyboardProc _keyboardProc = KeyboardInputCallback; | |
// メソッドを識別するID | |
private static IntPtr _mouseHookId = IntPtr.Zero; | |
private static IntPtr _keyboardHookId = IntPtr.Zero; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// マウス操作のイベントが発生したら実行されるメソッド | |
private static IntPtr MouseInputCallback (int nCode, IntPtr wParam, IntPtr lParam) { | |
if (nCode < 0) { | |
// マウスのイベントに紐付けられた次のメソッドを実行する。メソッドがなければ処理終了。 | |
return NativeMethods.CallNextHookEx (_mouseHookId, nCode, wParam, lParam); | |
} | |
MSLLHOOKSTRUCT param = Marshal.PtrToStructure<MSLLHOOKSTRUCT> (lParam); | |
Win32Point mousePosition = new Win32Point { |