-
-
Save whoeverest/0530f77704292d99bc3a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 os | |
def generate_file_paths(path): | |
for dirpath, dirlist, filelist in os.walk(path): | |
for f in filelist: | |
yield os.path.join(dirpath, f) | |
def create_filter(extension): | |
def filter_f(path): | |
return path.endswith(extension) | |
return filter_f | |
def lines(file_handle): | |
return sum(1 for line in file_handle) | |
paths = generate_file_paths('..') # sys.argv[1] | |
filt = create_filter('.js') # sys.argv[2] | |
s = 0 | |
for f_path in paths: | |
if not filt(f_path): | |
continue | |
s += lines(open(f_path)) | |
print s |
This file contains hidden or 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
------------------------------------ | |
-- Author: Nikola Minoski - June 2014 | |
-- Done in competition with Kex | |
-- Competition: Swift vs Lua | |
------------------------------------ | |
if #arg < 2 then | |
print "Usange: count_src_lines.lua <path_to_project_src_dir> <src_code_ext1> [<src_code_ext2 [...]]" | |
os.exit() | |
end | |
local dst = arg[1] | |
local allowedFiles = {} | |
for i=2,#arg do | |
allowedFiles[arg[i]:lower()] = true | |
end | |
require("lfs") | |
if not lfs.chdir(dst) then | |
print("Wrong src directory: '" .. dst .. "'") | |
os.exit() | |
end | |
local sourceLinesCount, sourceFiles = 0, 0 | |
function countLines(file) | |
sourceFiles = sourceFiles + 1 | |
local fd = io.open(file) | |
local count = 1 | |
while true do | |
local line = fd:read() | |
if line == nil then break end | |
if string.len(line:gsub("%s+", "")) > 0 then | |
sourceLinesCount = sourceLinesCount + 1 | |
end | |
end | |
fd:close() | |
end | |
function checkDir(folder) | |
for file in lfs.dir(folder) do | |
if file:sub(1, 1) ~= "." then | |
local path = folder .. "/" .. file | |
if lfs.attributes(path,"mode") == "file" then | |
local ext = file:match(".(%w-)$"):lower() | |
if allowedFiles[ext] then | |
countLines(path) | |
end | |
elseif lfs.attributes(path,"mode")== "directory" then | |
checkDir(path) | |
end | |
end | |
end | |
end | |
checkDir(dst) | |
print("Files: ", sourceFiles) | |
print("Source Lines: ", sourceLinesCount) |
This file contains hidden or 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
// Playground - noun: a place where people can play | |
// Done in competition with Nikola | |
// Competition: Swift vs Lua | |
import Cocoa | |
let fileManager:NSFileManager = NSFileManager.defaultManager() | |
let currentFilePath = "/Users/aleksandartrpeski/Documents/TMP/smashicons/BadIcons/BadIcons" | |
let paths:AnyObject[] = fileManager.subpathsAtPath(currentFilePath) | |
var linesOfCode = 0; | |
var files = 0; | |
for path:AnyObject in paths { | |
let filePath = currentFilePath.stringByAppendingPathComponent(path as String) | |
if filePath.pathExtension == "h" || | |
filePath.pathExtension == "m" || | |
filePath.pathExtension == "plist"{ | |
let text:AnyObject = NSString.stringWithContentsOfFile(filePath) | |
let count = text.componentsSeparatedByString("\n").count | |
linesOfCode += count | |
files++ | |
// println("\(count)\t\(text)") | |
} | |
} | |
println("\nLines of Code: \(linesOfCode)\n Files:\(files)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment