Skip to content

Instantly share code, notes, and snippets.

@ryochack
ryochack / serial_sample.go
Created November 8, 2020 21:43
Serial Write/Read sample using golang
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/tarm/serial"
)
#!/usr/bin/perl
use utf8;
use 5.010;
use strict;
#use autodie;
use warnings;
#use diagnostics;
my $who = `whoami`;
@ryochack
ryochack / tabstop.rs
Last active June 28, 2019 23:49
Get current tabstop
use std::io;
mod term {
use termios;
/// echo off. Return old termios state.
pub fn echo_off() -> termios::Termios {
let oldstat = termios::Termios::from_fd(0).unwrap();
let mut termstat = oldstat;
termstat.c_lflag &= !(termios::ICANON | termios::ECHO);
#include <memory>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
int main() {
std::unique_ptr<uint8_t[]> bufl(new uint8_t[320 * 240]);
memset(bufl.get(), 0x00, 320*240/2*sizeof(uint8_t));
memset(bufl.get()+320*240/2, 0x44, 320*240/2*sizeof(uint8_t));
#!/usr/bin/env bash
# This script is to set xrandr as mirroring
set -eu
DEBUG_ON=0
function log_output() {
if [[ $DEBUG_ON -ne 1 || $# -eq 0 ]]; then
@ryochack
ryochack / usbpower
Last active November 24, 2018 03:05
#!/usr/bin/env sh
#
# https://www.kernel.org/doc/Documentation/usb/power-management.txt
#
set -eu
USB_DEVICE_COUNTS=5
#!/usr/bin/env sh
#
# https://www.kernel.org/doc/Documentation/usb/power-management.txt
#
set -eu
function fn_help() {
use std::io;
#[derive(Debug)]
/// tuple-like struct
struct Foo(i32);
fn num(n: i32) -> io::Result<i32> {
Ok(n)
}
@ryochack
ryochack / linux.rs
Last active September 16, 2018 14:23
use std::fs::File;
use std::io::{self, Seek, SeekFrom};
use std::time::Duration;
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use mio;
use mio::unix::{EventedFd, UnixReady};
use nix::poll::{self, PollFd, EventFlags};
use libc::c_int;
use super::*;
use inotify;
extern crate mio;
use mio::unix::EventedFd;
use mio::{Token, PollOpt, Ready, Poll, Events};
use std::io::ErrorKind;
use std::time::Duration;
fn main() {
const IN: Token = Token(0);
let fd0_e = EventedFd(&0);