This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import ctypes.util | |
libc = ctypes.CDLL(ctypes.util.find_library('c')) | |
def if_nametoindex (name): | |
if not isinstance (name, str): | |
raise TypeError ('name must be a string.') | |
ret = libc.if_nametoindex (name) | |
if not ret: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang scheme/gui | |
(define new-game #t) | |
(define game-finished #f) | |
(define user-move #\X) | |
(define computer-move #\O) | |
(define move-count 0) | |
(define start-move user-move) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Implementation of static minimum variance huffman algorithm | |
(defun hf-get-symbol-table (string &key (for 'encode)) | |
;; Get the symbol table :for can be either encode or decode | |
;; For encode, the hashtable will use the symobls as keys | |
;; For decode, the hashtable will use the prefix codes as keys | |
(labels ((sort-func (x y) (< (cdr x) (cdr y))) | |
(build-tree (list) | |
(if (<= (length list) 2) | |
(cons (caar list) (caadr list)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Implementation of a simple variant of RLE | |
;; Algorithm | |
;; Whenever a character is repeated (appears 2 times), we put a number after it | |
;; which inidicate how many more times it is repeated. | |
;; For instance, "wwwwwwwwbb3333333123" will be decoded into"ww6bb0335123" | |
(defun rle-encode (string) | |
(loop as prev-char = #\Null then char | |
for char in (coerce string 'list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Implementation of static shanno-fano algorithm | |
;; Algorithm - (Taken from Wikipedia) | |
;; 1. For a given list of symbols, develop a corresponding list of probabilities | |
;; or frequency counts so that each symbol’s relative frequency of occurrence is known. | |
;; 2. Sort the lists of symbols according to frequency, with the most frequently | |
;; occurring symbols at the left and the least common at the right. | |
;; 3. Divide the list into two parts, with the total frequency counts of the left half | |
;; being as close to the total of the right as possible. | |
;; 4. The left half of the list is assigned the binary digit 0, and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def retry (function, retry=3): | |
@functools.wraps(function) | |
def wrapper (*args, **kwargs): | |
exception = None | |
for i in range (retry): | |
try: | |
return function (*args, **kwargs) | |
except Exception, ex: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path(File.dirname(__FILE__) + '/neo') | |
# Greed is a dice game where you roll up to five dice to accumulate | |
# points. The following "score" function will be used to calculate the | |
# score of a single roll of the dice. | |
# | |
# A greed roll is scored as follows: | |
# | |
# * A set of three ones is 1000 points | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# A small script for cdp devices discovery | |
import sys | |
import pcapy | |
import socket | |
from dpkt import ethernet | |
from dpkt import cdp | |
from docopt import docopt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# script for ubnt device discovery | |
# Usage: python discover.py or ./discover.py | |
import socket | |
from contextlib import closing | |
PORT=40860 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Author: Thura Hlaing <trhura@gmail.com> | |
# Time-stamp: <2013-08-29 16:13:36 (trhura)> | |
import os | |
import csv | |
from django.core.management.base import BaseCommand, CommandError | |
from django.db.models.loading import get_model |
OlderNewer