Skip to content

Instantly share code, notes, and snippets.

@atmb4u
atmb4u / newmd5.py
Created November 25, 2011 03:03
Basic self modifying code - puts the md5 of parent and last modified time. More info @ http://en.wikipedia.org/wiki/Self-modifying_code
import md5
f = open("newmd5.py","r+")
b = md5.md5(f.read())
# MD5 of the parent: 54062bcee8cdff7b3c3124421f5c5018 Last Modified:2011-11-21 23:28:46.974856
f.seek(60)
import datetime
digest = b.hexdigest()
f.writelines("# MD5 of the parent: "+digest+" Last Modified:"+str(datetime.datetime.now()))
print digest
f.close()
@atmb4u
atmb4u / choice.py
Created November 25, 2011 18:46
Another self modifying system which gets modified each timw someone accesses ut
import re
f = open("choice.py","r+")
i = 1###########This Number will get replaced
print "%s times" % (i)
f.seek(41)
c = f.readline()
m = re.match('\d+',c)
f.seek(41)
f.write(str(int(m.group())+1))
f.close()
@atmb4u
atmb4u / മലയാളം.py
Last active December 24, 2015 01:59
A quick proof that python unicode works; and it works beautifully! Python 3.x example.
class സൂചിക:
"""
മലയാളത്തിൽ പൈതോണ്‍ കോഡ് ചെയ്യാം എന്നുള്ളതിനുള്ള തെളിവ്
Proof that python can use malayalam language (Only on Python 3x)
"""
def സൂചിക(സ്വയം):
print(u"പൈതോണ്‍ ഇപ്പോൾ മലയാളത്തിലും !")
സൂചി = സൂചിക()
സൂചി.സൂചിക()
"""A simple implementation of a greedy transition-based parser. Released under BSD license."""
from os import path
import os
import sys
from collections import defaultdict
import random
import time
import pickle
SHIFT = 0; RIGHT = 1; LEFT = 2;
@atmb4u
atmb4u / simple.py
Created September 26, 2014 04:39
basic helloworld in flask
# import Flask object from flask library
# you can install flask by pip install flask
from flask import Flask
# initialize Flask app with the name of the file
app = Flask(__name__)
# define the url for which the application should send an http response to
@app.route('/')
# plain python function to handle the request
def hello_world():
@atmb4u
atmb4u / waterbottle.py
Created April 12, 2015 09:34
Function Pipelines with persistent State (FPS) - FPS programming
class WaterBottle(object):
def __init__(self):
self.water = 100
self.max_capacity = 500
self.make = "Plastic"
def add_water(self, amount):
if self.max_capacity < self.water + amount:
self.water = self.max_capacity
print "OverFlow"
@atmb4u
atmb4u / winebottle.py
Created April 12, 2015 09:36
Function Pipelines with persistent State (FPS) - FPS programming
class WineBottle(object):
def __init__(self):
self.wine = 100
self.max_capacity = 500
self.make = "Plastic"
def add_wine(self, amount):
if self.max_capacity < self.wine + amount:
self.wine = self.max_capacity
print "OverFlow"
@atmb4u
atmb4u / bottle_class.py
Last active August 29, 2015 14:19
Function Pipelines with persistent State (FPS) - FPS programming
class Bottle(object):
def __init__(self):
self.liquid = 100
self.name = ""
self.max_capacity = 500
self.make = "Plastic"
def print_details(bottle):
print bottle.liquid, bottle.name, bottle.max_capacity, bottle.make
@atmb4u
atmb4u / use_bottle.py
Created April 12, 2015 09:39
Function Pipelines with persistent State (FPS) - FPS programming
b = WaterBottle()
b.add_water(300)
b.drink_water(200)
b.drink_water(700)
b = WineBottle()
b.add_wine(300)
b.drink_wine(200)
b.drink_wine(700)
@atmb4u
atmb4u / urls.py
Created September 24, 2015 04:30
version info for django projects with git
#add this to your urls file
url(r'^version/$', 'api.views.code_version', name='code_version'),