Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
laclefyoshi / esp8266_mqtt_pub.ino
Last active October 17, 2015 13:18
ESP8266でMQTTブローカを経由しmyThingsにメッセージを投げる
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <PubSubClient.h>
#include <aJSON.h>
#define DHTPIN 4
#define DHTTYPE DHT11
const char* ssid = "WIFI_SSID";
const char* password = "WIFI_PASS";
@laclefyoshi
laclefyoshi / mqtt_sub.py
Created October 17, 2015 13:17
MQTTブローカからのメッセージを表示
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import paho.mqtt.client as mqtt_client
topic = "MESHBLU_ACTION_UUID"
def on_connect(client, userdata, flags, rc):
print("connected with result code" + str(rc))
client.subscribe(topic)
@laclefyoshi
laclefyoshi / gist:3925286
Created October 20, 2012 23:53
set font in emacs
(create-fontset-from-ascii-font
"Source Code Pro-14:weight=normal:slant=normal"
nil "codekakugo")
(set-fontset-font "fontset-codekakugo"
'unicode
(font-spec :family "Hiragino Kaku Gothic Pro" :size 16)
nil
'append)
(add-to-list 'default-frame-alist '(font . "fontset-codekakugo"))))
@laclefyoshi
laclefyoshi / gist:3883443
Created October 13, 2012 06:05
an example of MathML
<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<semantics>
<mtable>
<mtr>
<mtd>
<mrow>
<mrow>
<msup>
@laclefyoshi
laclefyoshi / gist:3830694
Created October 4, 2012 00:07
get indexies of local maximum values
#!/usr/bin/python
sample = [10, 11, 12, 1, 2, 3, 4, 2, 3]
temp = [0] + sample[0:-1]
points = map(lambda (x, y): x - 1,
            filter(lambda (i, v): v < 0,
                enumerate(map(lambda (a, b): a - b, zip(sample, temp)))))
if points[-1] != len(sample) - 1:
@laclefyoshi
laclefyoshi / test_phash.cpp
Created September 8, 2012 12:24
cpp code using phash
/**
Copyright: (c) SAEKI Yoshiyasu
License : MIT-style license
<http://www.opensource.org/licenses/mit-license.php>
last updated: 2012/09/08
**/
#include<cstdio>
#include<pHash.h>
@laclefyoshi
laclefyoshi / test_libpuzzle.c
Created September 8, 2012 11:42
c code using libpuzzle
/**
Copyright: (c) SAEKI Yoshiyasu
License : MIT-style license
<http://www.opensource.org/licenses/mit-license.php>
last updated: 2012/09/08
**/
#include<stdio.h>
#include<stdlib.h>
#include<puzzle.h>
@laclefyoshi
laclefyoshi / get_unused_port.py
Created June 16, 2012 07:55
get unused port
>>> import SocketServer
>>> ss = SocketServer.TCPServer(('localhost', 8080), None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 408, in __init__
self.server_bind()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 419, in server_bind
self.socket.bind(self.server_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
@laclefyoshi
laclefyoshi / get_unused_port.py
Created June 16, 2012 08:00
get unused port in Jython
>>> import socket
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sock.bind(('localhost', 0))
>>> sock.getsockname()
(u'127.0.0.1', 0)
>>> sock.listen(1)
>>> sock.getsockname()
(u'127.0.0.1', 49201)
>>> unused_port = _[1]
>>> sock.close()
@laclefyoshi
laclefyoshi / check_keys.py
Created May 26, 2012 05:28
check keys of Yahoo! Axis
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2012/05/26
import binascii
import subprocess