Skip to content

Instantly share code, notes, and snippets.

View lexrus's full-sized avatar
🏠
Working from home

Lex Tang lexrus

🏠
Working from home
View GitHub Profile
@lexrus
lexrus / rmsenseless.sh
Last active June 12, 2022 08:41
Remove senseless files from my NAS
#!/bin/bash
find . -name '*.DS_Store' -type f -delete;
find . -name 'Thumbs.db' -type f -delete;
find . -name '*.swp' -type f -delete;
find . -name '*.AppleDouble' -exec rm -rf {} \;
find . -name ".AppleDouble" -print0 | xargs -0 rm -rf;
find . -name ".TemporaryItems" -print0 | xargs -0 rm -rf;
find . -name ".Trashes" -print0 | xargs -0 rm -rf;
find . -name ".afpdeleted*" -print0 | xargs -0 rm -rf;
// Public domain - https://gist.github.com/nolanw/dff7cc5d5570b030d6ba385698348b7c
import Foundation
extension URLRequest {
/**
Configures the URL request for `multipart/form-data`. The request's `httpBody` is set, and a value is set for the HTTP header field `Content-Type`.
- Parameter parameters: The form data to set.
@lexrus
lexrus / naive_cam.py
Created December 26, 2021 07:22
Record videos for every single minute. Minimum requirements: Raspberry Pi Zero W and 12GB free space.
import picamera
from time import sleep
import datetime as dt
camera = picamera.PiCamera(resolution=(1024, 640), framerate=15)
camera.start_preview()
sleep(2)
camera.annotate_background = picamera.Color('black')
camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@lexrus
lexrus / FREEDOM.wsf
Created December 24, 2012 06:29
有些变态的公司不让员工安装一些 Windows 常用软件~ 这个脚本帮助你骗过运维的远程注册表扫描程序,“非法”安装一些应用。运行后会在桌面上生成已经安装的软件列表,选择哪些要假装删除,然后运行桌面上的这个脚本,运维就扫描不到了。
<job id="TheShawshankHammer">
<script language="JScript" id="env">
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = WScript.CreateObject("WScript.Shell");
var deskPath = WshShell.SpecialFolders("Desktop");
var arg = WScript.Arguments;
var scriptPath = WScript.ScriptFullName.split('\\').slice(0, -1).join('\\') + '\\';
</script>
<script language="JScript" id="scan">
@lexrus
lexrus / .gitignore
Created April 10, 2012 05:13
.gitignore
# Exclude the Podspecs
Pods/*
Podfile.lock
# Exclude any PSD/AI source
#*.psd
#*.ai
# Exclude generated files
VersionX-revision.h
@lexrus
lexrus / ToggleHDRCatalina.applescript
Created March 26, 2020 02:26
Workaround the HDR bug of macOS Catalina 10.15.4
tell application "System Preferences"
activate
end tell
tell application "System Events"
tell process "System Preferences"
activate
delay 1
click menu item "Displays" of menu "View" of menu bar 1
delay 1
@lexrus
lexrus / gems.sh
Last active January 18, 2019 09:13
Xcoder 常用工具一键安装
#!/bin/bash
# 解析 xcodeproj 的 Ruby 库 - https://github.com/CocoaPods/Xcodeproj
gem install --no-ri 'xcodeproj'
# xcoderbuild 的 Ruby 封装 - https://github.com/rayh/xcoder
gem install --no-ri 'xcoder'
# Xcode 工程配置工具 - https://github.com/thoughtbot/liftoff
gem install --no-ri 'liftoff'
@lexrus
lexrus / asicon.sh
Created March 6, 2012 08:48
AppStore Icons Generator
#!/bin/bash
# According to https://developer.apple.com/library/ios/#qa/qa1686/_index.html
# Install ImageMagick with MacPort: sudo port install ImageMagick
convert $1 -resize 512x512 iTunesArtwork.png # Ad Hoc iTunes
convert $1 -resize 144x144 Icon-72@2x.png # Home screen for "The New iPad"
convert $1 -resize 114x114 Icon@2x.png # Home screen for Retina display iPhone/iPod
convert $1 -resize 72x72 Icon-72.png # App Store and Home screen on iPad
convert $1 -resize 58x58 Icon-Small@2x.png # Spotlight and Settings for Retina display
convert $1 -resize 57x57 Icon.png # Home screen on non-Retina iPhone/iPod
convert $1 -resize 50x50 Icon-Small-50.png # Spotlight on iPad 1/2
@lexrus
lexrus / CollectionOperator.swift
Created April 24, 2017 08:53
Avoid hard-coded KVC collection operators
import Foundation
enum CollectionOperator: String {
case avg
case count
case max
case min
case sum
@lexrus
lexrus / createml.swift
Created June 29, 2018 13:27
CreateML 双色球
import Cocoa
import CreateML
let 双色球神算子 = try MLTextClassifier(trainingData: [
"中奖啦": [
"09 11 14 20 27 30 09",
"02 09 14 15 16 23 10",
"11 16 19 22 25 30 08",
"02 05 06 13 16 19 03",
"04 09 15 16 19 27 10",