Skip to content

Instantly share code, notes, and snippets.

@0xKD
0xKD / gist:4433678
Created January 2, 2013 10:36
DDA in C++
#include <iostream>
#define ROUND(a) ((int)(a + 0.5))
using namespace std;
int drawDDA(int x1,int y1,int x2,int y2)
{
float x = x1, y = y1;
int len = (x2-x1)>(y2-y1)?(x2-x1):(y2-y1);
float dx = (x2-x1)/(float)len;
@0xKD
0xKD / gist:4433688
Last active August 26, 2022 09:29
DDA in Python
def ROUND(a):
return int(a + 0.5)
def drawDDA(x1,y1,x2,y2):
x,y = x1,y1
length = abs((x2-x1) if abs(x2-x1) > abs(y2-y1) else (y2-y1))
dx = (x2-x1)/float(length)
dy = (y2-y1)/float(length)
print 'x = %s, y = %s' % (((ROUND(x),ROUND(y))))
for i in range(length):
@0xKD
0xKD / gist:4434880
Created January 2, 2013 14:17
Bresenham's line drawing algorithm ( for m <= 1 )
// Bresenham's line drawing algorithm ( for m <= 1 )
#include <iostream>
using namespace std;
int drawBH(int x1,int y1,int x2,int y2)
{
int x = x1, y = y1;
int dx = x2-x1;
int dy = y2-y1;
int e = 2*dy - dx;
@0xKD
0xKD / gist:4523076
Created January 13, 2013 09:02
BeautifulSoup 4 download and install script.
import urllib2
import tarfile
import os
url = 'http://pypi.python.org/packages/source/b/beautifulsoup4/beautifulsoup4-4.1.3.tar.gz'
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
@0xKD
0xKD / gist:4530035
Created January 14, 2013 13:22
Mid-point circle drawing algorithm implemented in Python
# Mid-point circle drawing algorithm.
# Requires pygame: http://pygame.org
from pygame import gfxdraw
import sys,pygame
pygame.init()
screen = pygame.display.set_mode((400,400))
screen.fill((0,0,0))
pygame.display.flip()
@0xKD
0xKD / gist:4714726
Last active December 12, 2015 04:28
DDA Line Drawing in Python using Pygame
import sys,pygame
from pygame import gfxdraw
pygame.init()
screen = pygame.display.set_mode((400,400))
screen.fill((0,0,0))
pygame.display.flip()
white=(255,255,255)
@0xKD
0xKD / gist:4714810
Created February 5, 2013 14:36
Bresenham line drawing in Python using Pygame
import sys,pygame
from pygame import gfxdraw
pygame.init()
screen = pygame.display.set_mode((400,400))
screen.fill((0,0,0))
pygame.display.flip()
white = (255,255,255)
def bresenham(x1,y1,x2,y2):
@0xKD
0xKD / gist:4731170
Created February 7, 2013 14:17
Ellipse drawing in Python using Pygame
from pygame import gfxdraw
import sys,pygame
pygame.init()
screen = pygame.display.set_mode((400,400))
screen.fill((0,0,0))
pygame.display.flip()
white = (255,255,255)
def symmetry(x,y):
@0xKD
0xKD / gist:4745862
Created February 9, 2013 16:14
Block a MAC address on the D-Link DSL-2750U
# Block a specific MAC address on the D-Link DSL-2750U (using parental control).
# May also work for other/similar D-Link routers (eg; 27xx)
import urllib,urllib2
import random,json,re
import base64
# Modify as necessary
login = base64.b64encode('admin:password') # username:password
mac = '00:00:00:00:00:00' # MAC address to block in the form xx:xx:xx:xx:xx:xx
@0xKD
0xKD / gist:6702928
Last active December 23, 2015 22:19
Get a list of all domain names from DNS queries in a tcpdump capture file.
import struct
def dns(capturefile, outputfile):
domains = []
cap = open(capturefile, 'rb')
cap.read(24)
try:
while True:
cap.read(8)