Skip to content

Instantly share code, notes, and snippets.

@keyo
keyo / gist:6087769
Last active December 20, 2015 06:39
odd_numbers = [x in range(0,100) if x % 2 == 1]
even_numver = [x in range(0,100) if x % 2 == 0]
@keyo
keyo / README.md
Created June 22, 2012 05:01
jQuery Field Dependencies

jQuery Field Dependencies

Author: Ben Brady Licensed: MIT

Overview

Allows selected elements to be changed (shown/hidden or callback) based on a set of field validation rules.

This is useful for large forms where you may want to hide/disable various fieldsets which are relevant only if a particular input element is selected/checked.

@keyo
keyo / hgfogbugz.py
Created May 3, 2012 04:40
HG Fogbugz Mercurial Extension
"""
HG Fogbugz Mercurial Extension
Prevents committing bad BugIDs
Add to .hgrc or mercurial.ini
[extensions]
fogbugz = C:\Users\User\hg_extensions\hgfogbugz.py
"""
@keyo
keyo / Counter.py
Created September 7, 2011 14:05
Python useless counter class
class Counter(object):
""" This class counts stuff... """
def __init__(self, start = 0, end = 10, increment = 1):
self.start = start
self.end = end
self.increment = increment
def __iter__(self):
# this method is called when a Counter object is used as an iterator (e.g. in a for loop).
i = self.start
@keyo
keyo / euler_project_17.py
Created August 19, 2011 15:34
Euler Project #17
'''
See http://projecteuler.net/index.php?section=problems&id=17
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.
'''
def num_letters(number):
digit_len = {1:3, 2:3, 3:5, 4:4, 5:4, 6:3, 7:5, 8:5, 9:4}
@keyo
keyo / gist:1027083
Created June 15, 2011 13:27
Text RPG
from collections import defaultdict
import re
class Location():
name = None
msg_arrive = 'Hi {player}, Welcome to {location_name}'
msg_depart = 'You leave {location_name}'
msg_look = 'You see {location_name}'