Skip to content

Instantly share code, notes, and snippets.

@kumajaya
kumajaya / node-red-dynamic-modbus.json
Created December 31, 2020 12:09
Modbus with dynamic IP, port, unit id, address, and quantity. Reuse node-modbus-serial from node-red-contrib-modbus package as external javascript in a function node
[
{
"id": "83890845.33fc58",
"type": "function",
"z": "82dda199.0531",
"name": "modbus",
"func": "var modbus = global.get('modbusserial');\nvar client = new modbus();\n\nclient.connectTelnet(msg.payload.ip, { port: msg.payload.port })\n .then(setClient)\n .then(function() {\n node.warn(\"Connected!\");\n node.status({fill:\"green\", shape:\"dot\", text:\"connected\"});\n })\n .catch(function(e) {\n node.error(\"Disconnected: \" + e.message);\n node.status({fill:\"red\", shape:\"ring\", text:\"disconnected: \" + e.message});\n });\n\nfunction setClient() {\n client.setID(msg.payload.unitid);\n client.setTimeout(10000);\n run();\n}\n\nfunction run() {\n client.readInputRegisters(msg.payload.address, msg.payload.quantity)\n .then(function(d) {\n msg.payload = d.data;\n node.send(msg);\n node.done();\n })\n .catch(function(e) {\n node.error(\"Error: \"
@niw
niw / fetch_nike_puls_all_activities.bash
Last active April 10, 2024 08:48
A simple NikePlus API description to fetch past run metrics
#!/usr/bin/env bash
# fetch_nike_puls_all_activities.bash
# A simple bash script to fetch all activities and metrics from NikePlus.
# See `nike_plus_api.md` for the API details.
readonly bearer_token="$1"
if [[ -z "$bearer_token" ]]; then
echo "Usage: $0 bearer_token"
exit
@sieyip
sieyip / README.md
Last active July 12, 2019 15:04
Installing Kafka on Mac OS X

Installing Kafka on Mac OS X

Install Homebrew

Homebrew is a great little package manager for OS X. If you haven't already, installing it is pretty easy:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
@naotokui
naotokui / conv_autoencoder_keras.ipynb
Created January 10, 2017 04:17
Convolutional Autoencoder in Keras
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@InsertNetan
InsertNetan / NSURL+Query.swift
Last active April 21, 2017 09:34
get the value of a specific query item within NSURL
extension NSURL {
func getQueryItemValueForKey(key: String) -> String? {
guard let components = NSURLComponents(URL: self, resolvingAgainstBaseURL: false) else {
return nil
}
guard let queryItems = components.queryItems else { return nil }
return queryItems.filter {
$0.name == key
}.first?.value
@karpathy
karpathy / min-char-rnn.py
Last active May 6, 2024 16:42
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@bcoe
bcoe / sanitize_string.rb
Last active July 10, 2018 14:50
Sanitize a search query for Lucene. Useful if the original query raises an exception, due to bad adherence to DSL. Taken from a discussion on Stack Overflow: http://stackoverflow.com/questions/16205341/symbols-in-query-string-for-elasticsearch
module ElasticSearchHelpers
# sanitize a search query for Lucene. Useful if the original
# query raises an exception, due to bad adherence to DSL.
# Taken from here:
#
# http://stackoverflow.com/questions/16205341/symbols-in-query-string-for-elasticsearch
#
def self.sanitize_string(str)
# Escape special characters
# http://lucene.apache.org/core/old_versioned_docs/versions/2_9_1/queryparsersyntax.html#Escaping Special Characters