Skip to content

Instantly share code, notes, and snippets.

@saknarak
saknarak / gist:516addf50280ddfbae49e8c82ed23a13
Created April 29, 2024 06:09
SQL Server: Identifying object closest to the end of a datafile
-- SOURCE https://dba.stackexchange.com/questions/187446/sql-server-identifying-object-closest-to-the-end-of-a-datafile
SET NOCOUNT ON;
-- Create Temp Table to push DBCC PAGE results into
CREATE TABLE #dbccPage_output(
ID INT IDENTITY(1,1)
, [ParentObject] VARCHAR(255)
https://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1
```sh
$ git init
Initialized empty Git repository in .git/
$ echo "testing reset" > file1
$ git add file1
$ git commit -m 'added file1'
Created initial commit 1a75c1d: added file1
# How to revert merge commit
- for keep uncommit
git reset --soft HEAD~1
- for reverse to commit point
git reset --hard HEAD~1
@saknarak
saknarak / gist:7d24743b42c9cf5c333498d6241759fb
Created January 17, 2024 11:06
Raspberry Pi with multiple USB webcams at high resolution
The secret is mode must be MJPG instead of default YUYV
```python
import cv2
cap0 = cv2.VideoCapture('/dev/video0')
cap0.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
cap0.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap0.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
@saknarak
saknarak / mysql-replication.md
Last active November 27, 2023 09:10
MySQL Replication Setup

MySQL Replication Setup (NOT GROUP REPLICATION)

  1. on mysql1 (master), and mysql2 (replica)
  • change server-id to 11 for mysql1, and 12 for mysql12 my.cnf
[mysqld]
default_authentication_plugin="mysql_native_password"
authentication_policy="caching_sha2_password"
slow_query_log
skip-name-resolve
@saknarak
saknarak / gist:88cee2fca2ee6c8ca11111e55e807c5d
Last active October 23, 2022 12:27
micropython to fix https request with timeout
# original from https://github.com/micropython/micropython-lib/blob/master/python-ecosys/urequests/urequests.py
import usocket
class Response:
def __init__(self, f, contentLength = -1, timeout=2):
self.raw = f
self.encoding = "utf-8"
self._cached = None
@saknarak
saknarak / http_client.py
Created June 20, 2021 15:43
micropython http client
import ujson as json
import uos as os
import usocket as socket
# original from https://gist.github.com/hiway/b3686a7839acca7d62e3a7234fdbb438
def http_get_async(url):
_, _, host, path = url.split('/', 3)
if ':' in host:
host, port = host.split(':')
@saknarak
saknarak / Fibo O(N)
Created August 21, 2018 03:53
Fibo O(N) JavaScript
function fibo(n) {
if (n <= 2) {
return 1
}
let a = 1
let b = 1
for (let i = 3; i < n; i++) {
b = a + b
a = b - a
https://github.com/felixrieseberg/windows-build-tools
npm --add-python-to-path --vs2017 install --global --production windows-build-tools
DECLARE item_cursor CURSOR LOCAL FAST_FORWARD FOR
SELECT conversation_handle FROM dbo.DRTrueCSSAccptQ1
OPEN item_cursor
DECLARE @conversation UNIQUEIDENTIFIER
FETCH NEXT FROM item_cursor INTO @conversation
WHILE @@FETCH_STATUS = 0
BEGIN
END CONVERSATION @conversation WITH CLEANUP
FETCH NEXT FROM item_cursor INTO @conversation
END