Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
filter by indentation level
<pre class='prettyprint' language='python'>#!/usr/bin/env python import sys, os try: treshold = int(sys.argv[1]) except IndexError: print "usage: %s TRESHOLD [INPUT_FILE]" % sys.argv[0] sys.exit(1) try: f = open(sys.argv[2]) except IndexError: f = sys.stdin indent_level = 0 lines_indented = 0 trunc_line_count = 0 whole = f.readlines() def count_leading_spaces(input_str): space_count = 0 for char in input_str: if char.isspace(): space_count += 1 else: return space_count def print_truncated_notice(): if trunc_line_count > 0: # suffer extra pain to pretty print a "truncated" line print " "*(indent_level) + "...", trunc_line_count, "line" + ('','s')[trunc_line_count != 1], "truncated ..." for line in whole: leading_spaces = count_leading_spaces(line) if leading_spaces == indent_level: lines_indented += 1 if lines_indented > treshold: trunc_line_count += 1 else: print line, else: print_truncated_notice() indent_level = leading_spaces trunc_line_count = 0 lines_indented = 1 print line, # did we truncate at the last indent level ? print_truncated_notice()</pre> <a href="http://www.refactormycode.com/codes/1041-filter-by-indentation-level" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>