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/python | |
# kills the process holding the TCP port passed as a command line argument | |
import subprocess | |
import os, sys | |
if len(sys.argv) < 2: | |
print "Missing argument: TCP port" | |
sys.exit(1) |
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
/** | |
* Returns the parent directory of a class being run by a web | |
* container, such as Tomcat. Useful for generating a | |
* value for iReport's SUBREPORT_DIR parameter. | |
* | |
* If using Struts 1.x, call this method this way: | |
<code> | |
getRealPath(getServlet().getServletContext(), YourClassName.class); | |
</code> | |
*/ |
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
def mod10(sequence): | |
factor = 1 | |
intermediate = "" | |
for i in range(len(sequence) - 1, -1, -1): | |
factor = 2 if factor == 1 else 1 | |
intermediate += str(int(sequence[i]) * factor) | |
remainder = sum([int(d) for d in intermediate]) % 10 | |
return 0 if remainder == 0 else 10 - remainder | |
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
def normalizar(nome) { | |
normalizado = "" | |
nome.toLowerCase().split().each {parte -> | |
if (!(parte =~ /^[e]$|^d[a-z]{1,2}$/)) { | |
parte = parte[0].toUpperCase() + parte.substring(1) | |
} | |
normalizado += parte + " " | |
} | |
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
String.prototype.padRight = function(length) { | |
var padding = ""; | |
for (i = 0; i < length - this.length; i++) { | |
padding += " "; | |
} | |
return this + padding; | |
} | |
String.prototype.trim = function() { |
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
def filter(file_name, re_filter) | |
File.open(file_name) do |f| | |
f.each_line.with_index {|line, i| yield line, i if line =~ re_filter} | |
end | |
end | |
#re_filter = /HTTP-404/ | |
re_filter = /ora-03113/i | |
filter('logs/error_log.1271160000', re_filter) do |line, i| |
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 | |
# Python Bitmap (bmp) Image Negation (using module struct) | |
import struct | |
with open('in.bmp', 'rb') as fd, open('out.bmp', 'wb') as out: | |
s = fd.read(1) | |
count = 1 | |
while s: | |
if count < 37: # header bytes |
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 | |
# Quicksort in Python | |
from random import randint | |
def sort(array): | |
def partition(array, left, right): | |
global swaps | |
# Improving worst case (at the cost of making average case suffer a little!) | |
#~ p = (left + right) // 2 |
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 | |
from time import sleep | |
i = 0 | |
while True: | |
print "Installing Clipper 5.2...", "|/-\\"[i], "\r", | |
i = (i + 1) % 4 | |
sleep 0.15 |
OlderNewer