Skip to content

Instantly share code, notes, and snippets.

@jaypei
jaypei / use_c_sleep.go
Last active May 9, 2024 15:12
Golang的调度机制决定Sleep是用户态实现的。但实现存在一个问题,若go程序在Sleep的过程中系统时间发生变化,Sleep会不准确,因为runtime中的实现是通过时间列表判断每个goroutine的挂起时间,而这个时间就是用的系统时间。这段代码是用cgo调用C的sleep规避这个问题的实现。
package main
/*
#include <unistd.h>
*/
import "C"
import (
"fmt"
"time"
)
@debkanchan
debkanchan / regex.md
Last active May 9, 2024 15:12
RegEx for Latitude and Longitude

Regular Expression(RegExp) for Latitude and Longitude

Just Latitude:

^-?([0-8]?[0-9]|90)(\.[0-9]{1,10})$

matches:

  • 56.3847
  • -56.387

unmatches:

@Klerith
Klerith / Instalaciones-React.md
Last active May 9, 2024 15:10
Instalaciones recomendadas para mi curso de React de cero a experto
@Quick104
Quick104 / readme.md
Last active May 9, 2024 15:07
Expose a server behind CG:NAT via Wireguard
@wojteklu
wojteklu / clean_code.md
Last active May 9, 2024 15:06
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@define-private-public
define-private-public / HttpServer.cs
Last active May 9, 2024 15:06
A Simple HTTP server in C#
// Filename: HttpServer.cs
// Author: Benjamin N. Summerton <define-private-public>
// License: Unlicense (http://unlicense.org/)
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Threading.Tasks;
@danielkwood
danielkwood / l293d_motor_code_with_ultrasonic.ino
Created February 28, 2023 03:13
L293D motor code with ultrasonic sensor
// First, download and unzip the Adafruit-Motor-Shield-library-master library from https://github.com/adafruit/Adafruit-Motor-Shield-library
// Extract the ZIP file and copy the folder into the Arduino/libraries directory (inside your Documents folder)
#include <AFMotor.h>
#define echoPin 9 // attach pin D9 on Arduino (SER1 on motor shield)) to ECHO pin on ultrasonic sensor
#define trigPin 10 // attach pin D10 on Arduino (SERVO_2 on motor shield) to TRIG pin on ultrasonic sensor
long duration; // duration of sound wave travel
int distance; // distance measured

MySQL Cheat Sheet

Help with SQL commands to interact with a MySQL database

MySQL Locations

  • Mac /usr/local/mysql/bin
  • Windows /Program Files/MySQL/MySQL version/bin
  • Xampp /xampp/mysql/bin

Add mysql to your PATH

@Misaka-0x447f
Misaka-0x447f / useHybridState.ts
Last active May 9, 2024 15:08
useHybridState.ts
import { isFunction, isObjectLike } from 'lodash-es'
import { useCallback, useRef, useState, useMemo, Dispatch, SetStateAction } from 'react'
/**
* @author 447f@misaka.org
* this hook allows reading an updated state value
* immediately by an extra ref.
* write to this ref is **not allowed** and should
* trigger an error.
* @example