Skip to content

Instantly share code, notes, and snippets.

View matchFloat.js
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 Mar 23, 2014
Broadcasting some strange packets.
View net_test.py
#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
View ip-down
#!/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 Mar 13, 2015
Reed-Solomon correction in GF(2^16), seems work.
View rs16.py
# 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
Apply correct Chinese name on AcFun.
View queble.user.js
// ==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 Nov 7, 2015 — forked from fdb713/twitter.mute.js
mute tweets containing specific keyword.
View twitter.mute.js
// 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
DHT11 on Arduino. Send temperature and humidity by serial.
View DHT11.ino
#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 Dec 17, 2015
Read acceleration from MMA7455L via I2C by Python.
View MMA7455L.py
#!/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 Jul 19, 2013
DHT22 on Arduino. Send temperature and humidity via serial.
View DHT22.ino
/*
* 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 Sep 4, 2013
Making the LED on router flash with traffic. http://sorz.org/flashled/
View flash-led.sh
#!/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