Skip to content

Instantly share code, notes, and snippets.

View gnuton's full-sized avatar
:shipit:

Antonio Aloisio gnuton

:shipit:
View GitHub Profile
@gnuton
gnuton / slowprint.py
Created February 14, 2016 09:17
Python slow print
import sys
import time
def slowprint(s):
for c in s + '\n':
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(1./10)
if __name__ == "__main__":
@gnuton
gnuton / README.md
Created February 1, 2016 10:07 — forked from teffalump/README.md
OpenWRT adblock implementation

Others have recently developed packages for this same functionality, and done it better than anything I could do. Use the packages instead of this script:

Description

In its basic usage, this script will modify the router such that blocked addresses are null routed and unreachable. Since the address blocklist is full of advertising, malware, and tracking servers, this setup is generally a good thing. In addition, the router will update the blocklist weekly. However, the blocking is leaky, so do not expect everything to be blocked.

#!/bin/ash
# This script filters the logs and send it via mail
# Installation on openwrt
#- opkg update && opkg install diffutils
#- install and setup ssmtp (https://fleshandmachines.wordpress.com/2014/09/14/openwrt-automatic-email-sending/)
#- add it to crontab
# Rules
RULES="grep -v info"
@gnuton
gnuton / cve_2016_0728.c
Created January 20, 2016 21:29 — forked from jpouellet/cve_2016_0728.c
cve_2016_0728 exploit
/* $ gcc cve_2016_0728.c -o cve_2016_0728 -lkeyutils -Wall */
/* $ ./cve_2016_072 PP_KEY */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <keyutils.h>
#include <unistd.h>
#include <time.h>
@gnuton
gnuton / gist:034e9353b51ab5af7ab8
Created January 13, 2016 16:37
Script to connect e3372s-153 stick firmware to internet on Linux
## Reference https://lists.openwrt.org/pipermail/openwrt-devel/2015-July/034094.html
import serial
from subprocess import call
from time import sleep
p='/dev/ttyUSB1'
def toIP(octet):
n=2
ipArray = [int(octet[i:i+n],16) for i in range(0, len(octet), n)][::-1]
@gnuton
gnuton / gist:3ba6dca3ce27d13833da
Created December 3, 2015 23:09
Python script which switch Huawey hilink e3372 to debug mode, then sends some command to its serial console.
import urllib2
# retrieve token
url="http://192.168.8.1/api/webserver/token"
response = urllib2.urlopen(url)
xml=response.read()
token=xml[59:-23]
print "Got token %s" % token
@gnuton
gnuton / gist:99f128f7587832f6a9b9
Created July 15, 2015 18:50
calculate logarithm in python
# complexity: logarihmic! :D
def log2(n):
result=0
while n > 1:
n//=2
result +=1
return result
import unittest
import math
@gnuton
gnuton / gist:513c67283bc4458dd3bd
Created December 2, 2014 15:01
Hijack STDERR and STDOUT stream - useful in tests
import sys
class MyStream(object):
S = property(lambda self: self._S)
def __init__(self):
self._S = ""
def write(self, s):
self._S += s
@gnuton
gnuton / Android services
Created October 18, 2013 17:54
Android Services in a nutshell
Android services in a nutshell
- Started when startService() is run by a component (activity or broadcast receiver)
-> Service.onStartCommand() runs in the Service
- Service stops when the service calls stopSelf() or a component calls stopService()
- If a component calls bindService() and onStartCommand() is not called
-> Service is stopped when all clients are unbound
- Runs in the application thread unless you don't set a different process name in the manifest file
- The more the service runs the more the service is susceptible to killing because
@gnuton
gnuton / gist:6810680
Created October 3, 2013 14:22
Small routine which converts a score to a color. 0.6 is the max value of the score
def color(score, max_score):
# proportion: max_score : 255 = score : x
nrmlzScore = int(score * 255 /max_score)
hueValue = (str(hex(abs(255 - nrmlzScore)))[2:])
colorHexStr = "#%s%s%s" %(hueValue,hueValue,hueValue)
print "%s -> %s" % (score, colorHexStr)
return colorHexStr