Skip to content

Instantly share code, notes, and snippets.

@JaosnHsieh
Last active September 13, 2023 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaosnHsieh/882dc5246c7f877898650b4bd35875fe to your computer and use it in GitHub Desktop.
Save JaosnHsieh/882dc5246c7f877898650b4bd35875fe to your computer and use it in GitHub Desktop.
2023-dev-notes

2023.02.03

Intercept proxy mitmweb

mitmweb: proxy server that able to intercept(pause/modify) http requests/responses for web/android/ios development

  1. Install mitmweb and start it by mitmweb -p 3033
  2. Setup proxy on android emulator setting -> proxy and set hostname to your local ip by $ ipconfig and 3033 port
  3. Open browser navigate to mitmweb localhost:8081 and on pause filter type ~u apikeyword

portable-python-in-electron.md

2023.05.19 electron packed portable python v3 and git example

ExpressLRS Configurator 1.5.9 https://github.com/ExpressLRS/ExpressLRS-Configurator/releases/tag/v1.5.9

on macOS, it installed portable python and git with electron installer to

~/Applications/ExpressLRS Configurator.app/Contents/dependencies/darwin_amd64/python-portable-darwin-3.8.4/

and

~/Applications/ExpressLRS Configurator.app/Contents/dependencies/darwin_amd64/git-2.29.2/

related code

const portableGitLocation = path.join(
      dependenciesPath,
      'darwin_amd64/git-2.29.2/bin'
    );
    PATH = prependPATH(PATH, portablePythonLocation);
    PATH = prependPATH(PATH, portableGitLocation);
    localApiServerEnv.GIT_EXEC_PATH = path.join(
      dependenciesPath,
      'darwin_amd64/git-2.29.2/libexec/git-core'
    );
  }

https://github.com/ExpressLRS/ExpressLRS-Configurator/blob/85d9b51eda73619b9feb0a38b4fcf2af69e9507a/src/main.dev.ts#L312-L322

      "extraFiles": [
        "dependencies/darwin_amd64",
        "dependencies/get-platformio.py"
      ]

https://github.com/ExpressLRS/ExpressLRS-Configurator/blob/85d9b51eda73619b9feb0a38b4fcf2af69e9507a/package.json#L65-L67

found by fd

2023.01.04

Same site response header

Refers to this article, as of Feb, 2020, setting 'samesite=none' in Set-Cookie http response header is necessary for Chrome browser.

I'm working on a react frontend app to a php server powered by symphony right now and the cookie and the cross-site http request is not working.

After testing:

It would work if response header set-cookie is set-cookie: connect.sid=s%3A0dEY7p75z15C_S4zafGq3aEnii6EayEg.nwM4BV%2BKGo8e9y9cMEtfFQZfnAZH51LiliJaPsaAJio; Path=/; HttpOnly; Secure; SameSite=None (tested on express.js)

It WON'T work if response header set-cookie is Set-Cookie: PHPSESSID=t4ejuk7sse0lir5v7juasj28b0; path=/; HttpOnly. (tested on symphony)

Secure; SameSite=None in set-cookie is a must for cross-site http request now.

Reproduce Steps

  1. Run a server with a domain that https enabled(nginx+cloudflare in my case)

server.js(node.js)

//@ts-nocheck

import express from 'express';
import session from 'express-session';
import cors from 'cors';

const app = express();

app.set('trust proxy', 1);
app.use(
  session({
    secret: 'keyboard cat',
    cookie: {
      secure: true,
      sameSite: 'none',
    },
  }),
);

app.use(cors({ credentials: true, origin: true }));

app.get('/', (req, res) => {
  if (req.session.test === 1) {
    return res.send('you got session id already it ');
  }
  req.session.test = 1;
  return res.send('just got session');
});

app.listen(3001, () => {
  console.log('listening to 3001');
});

client.js(chrome browser)

fetch('https://yourdomain.com/', {
  method: 'GET',
  redirect: 'follow',
  credentials: 'include',
})
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.log('error', error));

You should see just got session at the first request on client then see 'you got session id already it ' on second request since the cookie is attached cross-domain successfully

sqlcipher-open-db-file.md

db file path: ~/Desktop/mydb

make sure sqlcipher is installed, my version is SQLite version 3.42.0 2023-05-16 12:36:15 (SQLCipher 4.5.5 community)

  1. open the db file sqlcipher ~/Desktop/mydb
  2. PRAGMA key = 'your_password';
  3. it should reply ok
  4. try .tables to see tables or .schema to see schema

The Generics type Function(T a) is only allowed one paramter now. Not sure how to improve the type yet.

Usage

$ dart ./main.dart

0
2
4
6
8

main.dart

import 'dart:async';
import './throttle.dart';


void main() async {
  var f = Throttle.create((int n) {
    print(n);
  }, duration: const Duration(milliseconds: 1000));

  for (int i = 0; i < 10; i++) {
    f(i);
    await Future.delayed(Duration(milliseconds: 500));
  }
}

throttle.dart

import 'dart:async';

typedef ThrottledFunction<T> = Function(T a);

class Throttle<T> {
  Duration duration;
  Timer? _timer;
  ThrottledFunction<T>? _throttledFunction;

  Throttle(this._throttledFunction,
      {this.duration = const Duration(milliseconds: 500)});

  void call(T a) {
    if (_timer == null || !_timer!.isActive) {
      _timer = Timer(duration, () {
        _throttledFunction!(a);
        _timer = null;
      });
    }
  }

  static Throttle<T> create<T>(ThrottledFunction<T> function,
      {duration = const Duration(milliseconds: 500)}) {
    return Throttle(function, duration: duration);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment