Skip to content

Instantly share code, notes, and snippets.

View thetrung's full-sized avatar

Nguyễn Thế Trung thetrung

View GitHub Profile
@thetrung
thetrung / cpufreq-set-range
Last active February 15, 2025 14:53
Set all CPUs to a certain frequency range [ min, max] with cpufrequtils package.
#!/bin/bash
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check availability :
if [ cpufreq-set ]
@thetrung
thetrung / qclock.html
Created February 13, 2025 13:34
Clock Displayed by its own code.
<script>
(r=()=>setInterval(t=>{for(j=o="\n",y=5;y--;document.body["inn"
+"erHTML"]="<pre>&lt"+(S="script>\n")+o+"\n\n&lt/"+S)for(x=-01;
63-!y>x++;o+=`(r=${r})()`[j++].fontcolor(c?"#FF0":"#444"))c=x/2
%4<3&&parseInt("odRFacb67o2vi5gmOZmwFNteohbOh3sw".slice(i="9"<(
D=Date()[16+(x/8|0)])?30:D*3,i+3),36)&1<<(x/2|0)%4+3*y},100))()
</script>
@thetrung
thetrung / qlock.c
Created February 12, 2025 01:35 — forked from rexim/qlock.c
// cc -w -include time.h -o qlock qlock.c // MIT Copyright (c) Tsoding
char*s="// cc -w -include time.h -o qlock qlock.c // MIT Copyright (c) Tsoding\n"
"char*s=\"?\";x,y,d[8],i,dx;f[]={31599,19812,14479,31207,23524,29411,29679,\n"
"30866,31727,31719,1040};char*so,*si;p(ch){i=x/2/(3+2);dx=x/2%(3+2);if(i<8&&(y-5)\n"
"/2<5&&dx<3&&(f[d[i]]>>((5-(y-5)/2-1)*3+dx))&1)printf(\"\\033[1;41;30m%c\\033[0m\",ch\n"
");else printf(\"%c\",ch);if(ch=='\\n'){y+=1;x=0;}else x+=1;}gd(){time_t t=time(NULL);struct\n"
" tm*tm=localtime(&t);d[0]=tm->tm_hour/10;d[1]=tm->tm_hour%10;d[2]=10;d[3]=tm->tm_min\n"
"/10;d[4]=tm->tm_min%10;d[5]=10;d[6]=tm->tm_sec/10;d[7]=tm->tm_sec%10;}main(){for\n"
"(gd();;printf(\"\\n\\033[%dA\\033[%dD\",y+1,x),sleep(1),gd())for(so=s,x=0,y=0;*so;so++\n"
")if(*so==63)for(si=s;*si;si++)switch(*si){case'\\n':p('\\\\');p('n');p('\"');p('\\n')\n"
@thetrung
thetrung / hdmi_forward.sv
Created February 11, 2025 14:02
Forward HDMI signal on FPGA in SystemVerilog
module hdmi_forward (
input logic clk, // System clock
input logic reset, // Asynchronous reset
// HDMI inputs
input logic [2:0] tmds_i_red,
input logic [2:0] tmds_i_green,
input logic [2:0] tmds_i_blue,
input logic hsync_i,
input logic vsync_i,
@thetrung
thetrung / main.c
Created September 26, 2024 16:34
ESP32 Fetch BTC price from CoinDesk API
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>
// Change ID/PWD
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C Address of LCD 16x02
@thetrung
thetrung / PICKIT3_Tricks.md
Last active September 12, 2024 19:47
Pickit-3 on Ubuntu/IDE 6.20+

PICKIT-3 Programmer Tricks

When I first bought this old buddy, I thought it was dead, corrupted or something wrong there. But then, I figured it out after some late nights that it still work flawlessly with even latest MPLAB X IDE/IPE 6.20 on Ubuntu 24.04.1, even when USB Tools keep showing errors about some libusb_AccessLink_xyz not found. So lemme save you a day of googling ;)

1. Old firmware :

It does work flawlessly with Pickit-3 Programmer Standalone 3.10 Application but doesn't on MPLAB X IDE/IPE 6.20+.

  • This is because yours was flashed with old firmware/os/bootloader version from the seller, they tend to share/pre-flash it with this v3.10 program firmware so it can be recognized easily with it.

Solution :

@thetrung
thetrung / PlatformIO_Setup_Ubuntu.md
Last active September 12, 2024 15:28
Setup PlatformIO + CH32v / Ubuntu 24.04.1

How to setup PlatformIO & CH32 on Ubuntu 24.04.1

  1. Setup
  • Don't use sudo apt install platformio but if you did, try sudo apt remove platformio before proceeding further.

  • Install python-venv :

    sudo apt-get install python3-venv
    
  • Install PlatformIO :

@thetrung
thetrung / settings.json
Last active December 10, 2022 07:18
Settings-vsCode-10.Dec.2022
{
"workbench.startupEditor": "none",
"workbench.activityBar.visible": false,
// "workbench.editor.showIcons": false,
"editor.fontSize": 13.7,
// 3 columns section of Line-Number
// "editor.lineHeight": 26,
// "editor.folding": false,
@thetrung
thetrung / run_server.sh
Created September 8, 2020 16:05
Start SimpleHTTPServer in Background
#!/usr/bin/env bash
# Create a page in the current dir
echo "Init server..."
# Start server
python -m SimpleHTTPServer 8000 &> /dev/null &
pid=$!