Harigami
ログイン
Harigamiは、ログイン不要のコード共有サービスです。コードの投稿後に発行されるURLでコードを共有できます。
PythonやRubyなど一部の言語は、投稿後にオンラインで実行することもできます。
誰でも無料で使えて、広告もありません。コードレビューやスニペットの代わりに使ってみてください。


詳細設定
+
anonymous タッチとGPIOを同時に使う方法
C++
volatile uint32_t touchedTime = 0;

void IRAM_ATTR gotTouch() {
  touchedTime = millis();
}

void setup() {
  Serial.begin(115200);
  delay(50);

  touchAttachInterrupt(33, gotTouch, 10);
  pinMode(33, OUTPUT);
}

void loop() {
  if (millis() < touchedTime + 50) {
    digitalWrite(33, HIGH);
  } else {
    digitalWrite(33, LOW);
  }
  delay(1);
}
  • 0
  • 0
anonymous タイトルなし
Python
import smtplib, ssl
from email.mime.text import MIMEText
import datetime

# 以下にGmailの設定を書き込む★ --- (*1)
gmail_account = "******@gmail.com"
gmail_password = "password"
mail_to = "example@gmail.com"

def send_gmail(day_today, date_today) :
    week_num_of_mon = int(date_today.strftime('%d'))
    date_num = week_num_of_mon / 7
    subject_and_body = create_gmail_day_case(day_today, date_num)
    subject = subject_and_body[0]
    body = subject_and_body[1]
    msg = MIMEText(body, "html")
    msg["Subject"] = subject
    msg["To"] = mail_to
    msg["From"] = gmail_account

    server = smtplib.SMTP_SSL("smtp.gmail.com", 465,
        context=ssl.create_default_context())
    server.login(gmail_account, gmail_password)
    server.send_message(msg)
    print("ok.")

def create_gmail_day_case(day_of_week, date_num_mon) :
    if day_of_week == 0:
        subject = "ゴミ収集 きょうはありません"
        body = "今日は月曜日。 ゴミ収集はありません"
    elif day_of_week == 1:
        if date_num_mon <= 1:
            subject = "ゴミ収集 きょうは かん・びん"
            body = "今日は第一火曜日。 かん・びん ゴミの日です"
        elif date_num_mon >= 1 and date_num_mon <= 2:
            subject = "ゴミ収集 きょうは ペットボトル・雑がみ"
            body = "今日は第二火曜日。 ペットボトル・雑がみ ゴミの日です"
        elif date_num_mon >= 2 and date_num_mon <= 3:
            subject = "ゴミ収集 きょうは かん・びん"
            body = "今日は第三火曜日。 かん・びん ゴミの日です"
        elif date_num_mon >= 3 and date_num_mon <= 4:
            subject = "ゴミ収集 きょうは ペットボトル・雑がみ"
            body = "今日は第四火曜日。 ペットボトル・雑がみ ゴミの日です"
        else:
            return None
    elif day_of_week == 2:
        subject = "ゴミ収集 きょうは 燃やせるゴミ"
        body = "今日は水曜日。 燃やせるゴミの日です"
    elif day_of_week == 3:
        if date_num_mon <= 1:
            subject = "ゴミ収集 きょうは 大型ごみ"
            body = "今日は第一木曜日。 大型ごみの日です"
        elif date_num_mon >= 1 and date_num_mon <= 2:
            subject = "ゴミ収集 きょうは 燃やせないゴミ"
            body = "今日は第二木曜日。 燃やせないゴミの日です"
        elif date_num_mon >= 2 and date_num_mon <= 3:
            subject = "ゴミ収集 きょうは 紙パック・ダンボール"
            body = "今日は第三木曜日。 紙パック・ダンボール ゴミの日です"
        elif date_num_mon >= 3 and date_num_mon <= 4:
            subject = "ゴミ収集 きょうは 新聞ごみ"
            body = "今日は第四木曜日。 新聞 ゴミの日です"
        else:
            return None
    elif day_of_week == 4:
        subject = "ゴミ収集 きょうはありません"
        body = "今日は金曜日。 ゴミ収集はありません"
    elif day_of_week == 5:
        subject = "ゴミ収集 きょうは 燃やせるゴミ"
        body = "今日は土曜日。 燃やせるゴミの日です"
    elif day_of_week == 6:
        subject = "ゴミ収集 きょうはありません"
        body = "今日は日曜日。 ゴミ収集はありません"
    else:
        return None
    return subject, body

day = datetime.date.today().weekday()
date = datetime.datetime.today()
send_gmail(day, date)
  • 0
  • 1
anonymous タイトルなし
Java
import java.util.Scanner;
public class KuKuhyo {

	int x,y;
	int KuKu[][] = new int[10][10];
	
	Scanner scan = new Scanner(System.in);
	
	public void input() {
		
		for(int i = 0; i <= 9; i++) {
			for(int j = 0; j <= 9; j++) {
				KuKu[i][j] = (i+1)*(j+1);
			}
		}
		
		x = scan.nextInt();
		y = scan.nextInt();
		
		System.out.println(KuKu[x][y]); //(output)
	}
	public static void main(String[] args) {
		KuKuhyo Pro = new KuKuhyo();
		Pro.input();

	}

}
  • 0
  • 1
anonymous タイトルなし
JavaScript
/*雲除去の関数定義*/

function cloudMasking(image) {
  var qa = image.select('QA60');
  /*
  Bits 10 : dense(opaque) cloud
  Bits 11 : cirrus cloud
  */
  
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));
  return image.updateMask(mask).divide(10000);
}

var point = ee.Geometry.Point([138.1075,37.09666]);
Map.centerObject(point,17);


/*after*/
var start2 = ee.Date('2019-11-02');
var finish2 = ee.Date('2019-11-03');

var images2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate(start2, finish2)
.filterBounds(point);
//print(images2.size());

var image2b = ee.Image(images2.first());
var image2 = cloudMasking(image2b);

var truecolor2 = {bands:["B2","B3","B4"],min:0,max:0.3};
Map.addLayer(image2,truecolor2,'truecolor2');


//B8:NIR B4:R
var ndvi = image2.normalizedDifference(["B8","B4"])
.rename('NDVI2');

var landobs = {
bands:['NDVI2'],
min:0.0, max:1.0,
palette:['FFFFFF','CE7E45','DF923D','F1B555', 
           'FCD163','99B718','74A901','66A000', 
           '529400','3E8601','207401','056201',
           '004C00','023B01','012E01','011D01', 
           '011301']};


Map.addLayer(ndvi,landobs,'NDVI2');

var check_palette = ee.Algorithms.If(ndvi<0.4, ['00FF00'], ['FF0000']);

var land = {
bands:['NDVI2'],
min:0.0, max:1.0,
palette : check_palette};

Map.addLayer(ndvi,land,'check');
  • 0
  • 0
anonymous タイトルなし
JavaScript
/*雲除去の関数定義*/

function cloudMasking(image) {
  var qa = image.select('QA60');
  /*
  Bits 10 : dense(opaque) cloud
  Bits 11 : cirrus cloud
  */
  
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));
  return image.updateMask(mask).divide(10000);
}

/*主コード*/

var point = ee.Geometry.Point([138.1075,37.09666]);
Map.centerObject(point,17);

/*before*/
var start1 = ee.Date('2019-09-08');
var finish1 = ee.Date('2019-09-09');

var images1 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate(start1, finish1)
.filterBounds(point);
//print(images1.size());

var image1b = ee.Image(images1.first());
var image1 = cloudMasking(image1b);

var truecolor1 = {bands:["B2","B3","B4"],min:0,max:0.3};
Map.addLayer(image1,truecolor1,'truecolor1');


//B8:NIR B4:R
var ndvi = image1.normalizedDifference(["B8","B4"])
.rename('NDVI1');
var landobs = {
bands:['NDVI1'],
min:0.0, max:1.0,
palette:['FFFFFF','CE7E45','DF923D','F1B555', 
           'FCD163','99B718','74A901','66A000', 
           '529400','3E8601','207401','056201',
           '004C00','023B01','012E01','011D01', 
           '011301']};
Map.addLayer(ndvi,landobs,'NDVI1');


/*after*/
var start2 = ee.Date('2019-11-02');
var finish2 = ee.Date('2019-11-03');

var images2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate(start2, finish2)
.filterBounds(point);
//print(images2.size());

var image2b = ee.Image(images2.first());
var image2 = cloudMasking(image2b);

var truecolor2 = {bands:["B2","B3","B4"],min:0,max:0.3};
Map.addLayer(image2,truecolor2,'truecolor2');


//B8:NIR B4:R
var ndvi = image2.normalizedDifference(["B8","B4"])
.rename('NDVI2');
var landobs = {
bands:['NDVI2'],
min:0.0, max:1.0,
palette:['FFFFFF','CE7E45','DF923D','F1B555', 
           'FCD163','99B718','74A901','66A000', 
           '529400','3E8601','207401','056201',
           '004C00','023B01','012E01','011D01', 
           '011301']};
Map.addLayer(ndvi,landobs,'NDVI2');
  • 0
  • 0
anonymous タイトルなし
JavaScript
/*主コード*/

var point = ee.Geometry.Point([138.1075,37.09666]);
Map.centerObject(point,17);

/*before*/
var start1 = ee.Date('2019-09-08');
var finish1 = ee.Date('2019-09-09');

var images1 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate(start1, finish1)
.filterBounds(point);
//print(images1.size());

var image1 = ee.Image(images1.first());

var truecolor1 = {bands:["B2","B3","B4"],min:0,max:3000};
Map.addLayer(image1,truecolor1,'truecolor1');


//B8:NIR B4:R
var ndvi = image1.normalizedDifference(["B8","B4"])
.rename('NDVI1');
var landobs = {
bands:['NDVI1'],
min:0.0, max:1.0,
palette:['FFFFFF','CE7E45','DF923D','F1B555', 
           'FCD163','99B718','74A901','66A000', 
           '529400','3E8601','207401','056201',
           '004C00','023B01','012E01','011D01', 
           '011301']};
Map.addLayer(ndvi,landobs,'NDVI1');


/*after*/
var start2 = ee.Date('2019-11-02');
var finish2 = ee.Date('2019-11-03');

var images2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate(start2, finish2)
.filterBounds(point);
//print(images2.size());

var image2 = ee.Image(images2.first());

var truecolor2 = {bands:["B2","B3","B4"],min:0,max:3000};
Map.addLayer(image2,truecolor2,'truecolor2');


//B8:NIR B4:R
var ndvi = image2.normalizedDifference(["B8","B4"])
.rename('NDVI2');
var landobs = {
bands:['NDVI2'],
min:0.0, max:1.0,
palette:['FFFFFF','CE7E45','DF923D','F1B555', 
           'FCD163','99B718','74A901','66A000', 
           '529400','3E8601','207401','056201',
           '004C00','023B01','012E01','011D01', 
           '011301']};
Map.addLayer(ndvi,landobs,'NDVI2');
  • 0
  • 0
anonymous タイトルなし
JavaScript
var point = ee.Geometry.Point([138.25,37.15]);
//var point = ee.Geometry.Point([138,35.15]);
Map.centerObject(point,11);

var start = ee.Date('2019-10-11');
var finish = ee.Date('2019-10-19');

var images = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate(start, finish)
.filterBounds(point);

var image = ee.Image(images.first());

print(images.size());
//B8:NIR B4:R
var truecolor = {bands:["B2","B3","B4"],min:0,max:5000};
Map.addLayer(image,truecolor,'truecolor');

var ndvi = image.normalizedDifference(["B8","B4"])
.rename('NDVI');
var landobs = {
bands:['NDVI'],
min:0.0, max:1.0,
palette:['0000FF','000000','00FF00']};
Map.addLayer(ndvi,landobs,'NDVI');
  • 0
  • 0
anonymous タイトルなし
C
void rev(char *p,int size){
   char x;
   for(int i = 0;i < size/2;i++){
      x = p[i];
      p[i] = p[size-1-i];
      p[size-1-i] = x;
   }
}
  • 0
  • 0
anonymous タイトルなし
Python
Today every person on Earth has been affected by the COVID-19 outbreak. Airplanes are grounded, borders are closed, businesses are shut, citizens are forced into quarantine, and governments are taking spontaneous emergency decisions undermining the principles of democracy. 
All this, if not stopped shortly, can lead to chaos and unrests. 
Currently HTTP://WWW.ST-lF.COM  is proud to represent the world-wide scientific community, by fundraising for COVID-19 Vaccine Development. 
It is a responsibility of every human-being to put every effort to fight the deadly virus. Your support is needed to develop a vaccine ASAP! Every 1$ makes a difference. 
Please, take a moment to review our campaigns HTTP://WWW.ST-lF.COM
  • 0
  • 0
anonymous タイトルなし
Python
  • 0
  • 0