Skip to content

Instantly share code, notes, and snippets.

View nazt's full-sized avatar

Nat nazt

  • Chiang Mai Maker Club
  • Chiang Mai
  • X @nazt
View GitHub Profile
@nazt
nazt / README-setup-tunnel-as-systemd-service.md
Created March 3, 2018 02:16 — forked from drmalex07/README-setup-tunnel-as-systemd-service.md
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/[email protected]. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target
@nazt
nazt / ngrok-selfhosting-setup.md
Created June 27, 2018 04:48 — forked from lyoshenka/ngrok-selfhosting-setup.md
How to setup Ngrok with a self-signed SSL cert

Intro

The plan is to create a pair of executables (ngrok and ngrokd) that are connected with a self-signed SSL cert. Since the client and server executables are paired, you won't be able to use any other ngrok to connect to this ngrokd, and vice versa.

DNS

Add two DNS records: one for the base domain and one for the wildcard domain. For example, if your base domain is domain.com, you'll need a record for that and for *.domain.com.

Different Operating Systems

@nazt
nazt / gist:04f3b890219a00c6aff0b79c22c0b04d
Created June 30, 2018 05:05 — forked from xsleonard/gist:7341172
hex string to byte array, C
unsigned char* hexstr_to_char(const char* hexstr)
{
size_t len = strlen(hexstr);
IF_ASSERT(len % 2 != 0)
return NULL;
size_t final_len = len / 2;
unsigned char* chrs = (unsigned char*)malloc((final_len+1) * sizeof(*chrs));
for (size_t i=0, j=0; j<final_len; i+=2, j++)
chrs[j] = (hexstr[i] % 32 + 9) % 25 * 16 + (hexstr[i+1] % 32 + 9) % 25;
chrs[final_len] = '\0';
@nazt
nazt / thingy-server.js
Created November 2, 2018 04:53 — forked from DurandA/thingy-server.js
Thingy:52 Web Thing server using webthing-node
const {Action, Event, Property, Thing, WebThingServer} = require('./index');
const uuidv4 = require('uuid/v4');
var Thingy = require('thingy52');
var Color = require('color');
console.log('Reading Thingy environment sensors!');
class ButtonEvent extends Event {
constructor(thing, state) {
@nazt
nazt / image.resize.in.github.flavored.markdown.md
Created January 18, 2019 03:13 — forked from uupaa/image.resize.in.github.flavored.markdown.md
image resize in github flavored markdown.

Image source

https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png

Try resize it!

  • ![](https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png | width=100)
@nazt
nazt / node-s.js
Last active January 26, 2019 15:14 — forked from allfake/node-s
node-s.js
const SerialPort = require('serialport')
const port = new SerialPort('/dev/tty.usbmodem0006826707061', {
baudRate: 9600//115200
})
const Delimiter = require('@serialport/parser-delimiter')
const parser = port.pipe(new Delimiter({ delimiter: '\n' }))
// console.log(Buffer.from([0xff]))
const delay = require('delay');
If you follow instruction at https://github.com/RAKWireless/RUI_Platform_Firmware_GCC.
And work, that will be fine. For me, that not work well. I feel like i live in space. Yeah!
Install arm-none-eabi
DO NOT USE LASTEST VERSION -> i use version 7.2.1 (GNU Tools for Arm Embedded Processors 7-2017-q4-major)
You can use lower version
- download from here https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads/7-2017-q4-major-1-1
[Check here for more information https://gist.github.com/joegoggins/7763637]
In winodw if you use cygwin that RAKWireless recommended, you NEED to install "make" too. Because "make" not include.
@nazt
nazt / 1-standard.js
Created August 25, 2019 15:05 — forked from vladfr/1-standard.js
Use async/await and for..of in Cloud Firestore
// In a Firestore standard example, we quickly create a 'xmas tree' of nested stuff
// We use Promises directly: get().then(callback) and use snapshot.forEach() to iterate
let campaignsRef = db.collection('campaigns');
let activeCampaigns = campaignsRef.where('active', '==', true).select().get()
.then(snapshot => {
snapshot.forEach(campaign => {
console.log(campaign.id);
let allTasks = campaignsRef.doc(campaign.id).collection('tasks').get().then(
snapshot => {
snapshot.forEach(task => {
@nazt
nazt / showarray.py
Created October 18, 2019 06:37 — forked from kylemcdonald/showarray.py
Minimal code for rendering a numpy array as an image in a Jupyter notebook in memory. Borrowed from the Deep Dream notebook.
import PIL.Image
from cStringIO import StringIO
import IPython.display
import numpy as np
def showarray(a, fmt='png'):
a = np.uint8(a)
f = StringIO()
PIL.Image.fromarray(a).save(f, fmt)
IPython.display.display(IPython.display.Image(data=f.getvalue()))
from matplotlib import pyplot as plt
import cv2
img = cv2.imread('/Users/mustafa/test.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
plt.imshow(gray)
plt.title('my picture')
plt.show()