Skip to content

Instantly share code, notes, and snippets.

View sorz's full-sized avatar
😱
AAHHH

Shell Chen sorz

😱
AAHHH
View GitHub Profile
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++)
@sorz
sorz / net_test.py
Created March 23, 2014 10:32
Broadcasting some strange packets.
#encoding: UTF-8
import sys
import time
import random
from socket import inet_aton
from ctypes import *
from winpcapy import *
from dpkt.ip import IP, IP_PROTO_TCP
from dpkt.tcp import TCP
#!/bin/sh
PPP_IFACE="$1"
PPP_TTY="$2"
PPP_SPEED="$3"
PPP_LOCAL="$4"
PPP_REMOTE="$5"
PPP_IPPARAM="$6"
if [ "$PPP_IFACE" = "ppp0" ]
@sorz
sorz / rs16.py
Created March 13, 2015 10:10
Reed-Solomon correction in GF(2^16), seems work.
# Modified from
# http://en.wikiversity.org/wiki/Reed–Solomon_codes_for_coders
gf_exp = [0] * 65536 * 2 # Create list of 65536 elements. In Python 2.6+, consider using bytearray
gf_log = [0] * 65536
gf_exp[0] = 1
x = 1
for i in range(1, 65535):
x <<= 1
if x & 0x10000:
@sorz
sorz / queble.user.js
Created May 3, 2015 12:24
Apply correct Chinese name on AcFun.
// ==UserScript==
// @name 缺B乐
// @namespace org.sorz.lab.queble
// @include http://www.acfun.tv/*
// @version 1
// @grant none
// ==/UserScript==
String.prototype.correct = function () {
return this.toString()
@sorz
sorz / twitter.mute.js
Last active November 7, 2015 08:29 — forked from fdb713/twitter.mute.js
mute tweets containing specific keyword.
// origin: @ayanamist
// ==UserScript==
// @name Twitter Keyword Filter
// @namespace Twitter-Timeline-URL-Expand
// @description Replace t.co href of A tag with real url.
// @match https://twitter.com/
// @version 1.1
// ==/UserScript==
(function (window) {
var document = window.document;
@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 / 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 / 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 / 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