Skip to content

Instantly share code, notes, and snippets.

View sorz's full-sized avatar
😱
AAHHH

Shell Chen sorz

😱
AAHHH
View GitHub Profile
@sorz
sorz / MMA7455L.py
Last active December 17, 2015 05:49
Read acceleration from MMA7455L via I2C by Python.
#!/usr/bin/env python
import smbus
import time
class Accel():
def __init__(self, dev=1, g=2):
self.bus = smbus.SMBus(dev)
self.set_range(g)
@sorz
sorz / DHT11.ino
Created May 11, 2013 18:33
DHT11 on Arduino. Send temperature and humidity by serial.
#define DHT11_PIN 2
void setup() {
pinMode(DHT11_PIN, INPUT_PULLUP);
Serial.begin(115200, SERIAL_8E1);
}
void loop() {
if (Serial.available() > 0) {
byte in = Serial.read();
@sorz
sorz / gfwlist2regex.py
Last active July 13, 2021 16:57
Download and convert GFWList to url regex which compatible with Squid.
#!/usr/bin/env python
#encoding: utf-8
import urllib2
from base64 import b64decode
LIST_URL = 'https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt'
BLACK_FILE = 'gfw.url_regex.lst'
WHITE_FILE = 'cn.url_regex.lst'
@sorz
sorz / hw_smsd.py
Last active December 23, 2016 12:17
Forward SMS to E-mail via Huawei datacard. See https://blog.sorz.org/p/sms2email/ for detial.
#!/usr/bin/env python
#encoding: utf-8
# Copyright (C) 2013 @XiErCh
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@sorz
sorz / DHT22.ino
Created July 19, 2013 15:26
DHT22 on Arduino. Send temperature and humidity via serial.
/*
* Author: @xierch
* License: MIT
* Known Issues: can't throw timeout exception if DHT22 broken.
*/
#define DHT22_PIN 2
void setup() {
pinMode(DHT22_PIN, INPUT_PULLUP);
@sorz
sorz / DS1307.py
Last active September 5, 2019 19:48
Read and wite datetime on DS1307 via I2C by Python.
#!/usr/bin/env python
#encoding: utf-8
# Copyright (C) 2013 @XiErCh
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@sorz
sorz / flash-led.sh
Created September 4, 2013 17:02
Making the LED on router flash with traffic. http://sorz.org/flashled/
#!/bin/sh
#set -x
export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
IFNAME="eth0"
FULLSPEED=1200 # KiB/s
LED='/sys/class/leds/tp-link:blue:system/brightness'
while [ True ]
do
@sorz
sorz / sendudp.py
Created September 28, 2013 18:21
Send UDP packets from any custom port (using libnet). Used for UDP hole punching on linux servers (when the local UDP port is being used).
#!/usr/bin/env python
#encoding: utf-8
import libnet
from libnet.constants import RAW4, RESOLVE, IPV4_H, UDP_H, IPPROTO_UDP
IFACE = 'wlan2' # Sending via the interface.
def sendto(sport, address):
l = libnet.context(RAW4, IFACE)
#!/usr/bin/python
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('0.0.0.0', 6000))
while True:
data, addr = s.recvfrom(1024)
s.sendto(str(addr[1]), addr)
function matchFloat(s) {
f = s.replace(/[^\d]+/g, '');
g = s.split(/\d/);
if (g.length == 0)
return f;
else if (g[0].contains('-'))
f = '-' + f;
for (var i=0; i<g.length - 1; i++)