Skip to content

Instantly share code, notes, and snippets.

@dragonken
dragonken / mac-mail-regex-search.applescript
Created December 29, 2023 06:48 — forked from BrettBukowski/gist:5347463
Filter emails in Mail.app with regular expressions
-- Mail.app can't run a "Contains" filter with a regex,
-- so you can't filter on HTML content. Until now.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
try
repeat with theMessage in theMessages
-- Getting the content as string converts all HTML tags to '?' and just leaves text content
set theBody to quoted form of (theMessage's content as string)
-- It's awkwardly hard to get sed to work w/ mult. lines, so collapse newlines
set theCommandString to "echo " & theBody & " | tr '\\n' ' ' | sed \"s/brett Author/*MATCHED*(&)/\"" as string
@dragonken
dragonken / json-val.sh
Last active January 9, 2021 20:53 — forked from cjus/jsonval.sh
Extract a JSON value from a BASH script
#!/bin/bash
function jsonval {
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop`
echo ${temp##*|}
}
json=`curl -s -X GET http://twitter.com/users/show/$1.json`
prop='profile_image_url'
picurl=`jsonval`
#!/bin/bash
# Convert all files to Traditional Chinese
for f in * ; do mv $f `echo $f | cconv -f UTF-8 -t UTF8-HK` ; done
@dragonken
dragonken / start.sh
Last active March 30, 2019 17:48
shall Alias
# Frequent use alias
alias copypath='pwd|pbcopy'
alias dlmp3='youtube-dl -x --audio-format mp3'
alias detectvolume='ffmpeg -vn -sn -dn -af "volumedetect" -f null /dev/null -i'
setopt HIST_SAVE_NO_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_FIND_NO_DUPS
unsetopt share_history
from ctypes import *
import pyHook
import pythoncom
import win32clipboard
import sys
current_window = None
current_command = False
user32 = windll.user32
@dragonken
dragonken / ch4_arp_poison.py
Created March 9, 2019 22:33 — forked from ismailakkila/ch4_arp_poison.py
ch4_arp_poison.py
from scapy.all import *
import os
import signal
import sys
import threading
import time
#ARP Poison parameters
gateway_ip = "10.0.0.1"
target_ip = "10.0.0.250"
@dragonken
dragonken / npm-using-https-for-git.sh
Created November 17, 2018 08:47 — forked from taoyuan/npm-using-https-for-git.sh
Force git to use https:// instead of git://
git config --global url."https://github.com/".insteadOf [email protected]:
git config --global url."https://".insteadOf git://
@dragonken
dragonken / Instructions
Created November 4, 2018 21:27 — forked from halbtuerke/Instructions
Join multiple *.flv files with ffmpeg
To use this script just copy all flv files into a directory and call the script via:
"join-flvs.sh *.flv"
@dragonken
dragonken / gitconfig.sh
Last active June 16, 2023 13:24
Add git config
# From http://garmoncheg.blogspot.com/2012/06/pretty-git-log.html
git config --global alias.lg1 "log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"
git config --global alias.lg2 "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all"
git config --global alias.lg \!"git lg1"
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.st "status"
pair = 'BTCUSD'
csv = [['Date', 'Open', 'High', 'Low', 'Close', 'Volume']]
end_t = Time.now.to_i * 1000
loop do
body = HTTParty.get("https://api.bitfinex.com/v2/candles/trade:1h:t#{pair}/hist?_bfx=1&limit=1500&end="+end_t.to_s).body
body = Oj.load(body) rescue nil
break if body.nil?
break if body.size == 0
body.each do |e|
csv << [Time.at(e[0] / 1000).strftime('%Y-%m-%d %H:00:00'), e[1], e[3], e[4], e[2], e[5]]