Skip to content

Instantly share code, notes, and snippets.

@qqwqqw689
qqwqqw689 / prng.c
Created September 14, 2024 04:42
Portable pseudorandom number generator in c.
/* Portable pseudorandom number generator
* Based on a 24,55 Fibonacci generator, using 55/503 rejection
* c.f.- TAoCP, 3.2.2(7), for j=24,k=55,m=2^64
*
* THIS FILE IS PUBLIC DOMAIN CODE.
*
* Written by Bob Adolf.
* Attribution is appreciated but by no means legally required.
*
* This function is sufficient for most non-crypto applications.
@qqwqqw689
qqwqqw689 / I2C_LCD_driver.py
Created September 12, 2024 16:22
I2C_LCD_driver python
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Original code found at:
# https://gist.github.com/DenisFromHR/cc863375a6e19dce359d
"""
Compiled, mashed and generally mutilated 2014-2015 by Denis Pleic
Made available under GNU GENERAL PUBLIC LICENSE
@qqwqqw689
qqwqqw689 / screenshot.md
Last active September 7, 2024 06:26
Window Screen Capture Using Pywin32.
import win32gui, win32ui, win32con

def test_get_screenshot():
    # define your monitor width and height
    w, h = 1920, 1080

    # for now we will set hwnd to None to capture the primary monitor
    #hwnd = win32gui.FindWindow(None, window_name)
    hwnd = None
@qqwqqw689
qqwqqw689 / Producer_Consumer.cpp
Created July 19, 2024 01:39
Producer-Consumer-Problem.
#include <iostream> // Includes the standard I/O library
#include <queue> // Includes the queue library for queue operations
#include <thread> // Includes the thread library for threading operations
#include <mutex> // Includes the mutex library for synchronization
#include <condition_variable> // Includes the condition_variable library for thread communication
std::mutex mtx; // Declares a mutex for critical section management
std::condition_variable cond_var; // Declares a condition variable for blocking and waking threads
std::queue<int> buffer; // Declares a queue to act as the buffer
const unsigned int MAX_BUFFER_SIZE = 10; // Sets the maximum size of the buffer
@qqwqqw689
qqwqqw689 / file.md
Created July 13, 2024 14:34
Number of Binary Trees for given Preorder Sequence length.
@qqwqqw689
qqwqqw689 / file.md
Created July 13, 2024 12:46
Inorder Tree Traversal without Recursion
// C++ program to print inorder traversal
// using stack.

#include <bits/stdc++.h>
using namespace std;

// A binary tree Node has data, pointer to left child
// and a pointer to right child
struct Node {
@qqwqqw689
qqwqqw689 / ThreadedBinaryTree.cpp
Created June 30, 2024 06:36
Threaded Binary Tree(unread)
#include <iostream>
#include <cstdlib>
#define MAX_VALUE 65536
using namespace std;
class N { //node declaration
public:
int k;
N *l, *r;
bool leftTh, rightTh;
};
@qqwqqw689
qqwqqw689 / wallpaper.md
Last active July 20, 2024 01:08
python script : wallpaper of himawari8.
# Use latest himawari 8 photo as wallpaper
# for Windows user

from datetime import datetime, timezone, timedelta
import requests
import ctypes
from PIL import Image, ImageDraw, ImageFont
import cv2
import numpy as np
@qqwqqw689
qqwqqw689 / MPIsort.cpp
Last active July 2, 2024 13:04
MPI sort example.
#include <mpi.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
void bubble_sort(std::vector<int>& arr) {
int n = arr.size();
for (int i = 0; i < n - 1; ++i) {
@qqwqqw689
qqwqqw689 / markdown.md
Last active May 23, 2024 08:39
Converting between Windows and Linux line breaks.

The Windows and Linux operating systems have a slight variation in how they handle newlines in files. Typically, in the Windows environment a line is terminated with the two characters \r\n. The \r character represents a carriage return, and \n represents a newline. In Linux, only the \n character is used to terminate a line.

This causes some interesting behavior issues when moving between the Windows and Linux environment. For example, if you have a multi-line text file that was created in Linux, and then try to open it using a program such as Windows Notepad, the entire contents of the file will appear on a single line.

Converting from Linux to Windows Line Breaks