Archive for November 2009
331 viewsswitch (mIntegrationDirection)
{
case InventoryIntegrationDirection.DoTheSameChangeInShop:
DoTheSameChangeInShop(GetChangedDataFromInventory(mLastSynchDate));
break;
case InventoryIntegrationDirection.DoTheSameChangeInInventory:
DoTheSameChangeInInventory(GetChangedDataFromShop(mLastSynchDate));
break;
case InventoryIntegrationDirection.DoTheSameChangeInShopThenDoTheSameChangeInInventoryForNotChangedDataInInventory:
DoTheSameChangeInShopThenDoTheSameChangeInInventoryForNotChangedDataInInventory(
GetChangedDataFromInventory(mLastSynchDate),
GetChangedDataFromShop(mLastSynchDate));
break;
case InventoryIntegrationDirection.DoTheSameChangeInInventoryThenDoTheSameChangeInShopForNotChangedData:
DoTheSameChangeInInventoryThenDoTheSameChangeInShopForNotChangedData(
GetChangedDataFromShop(mLastSynchDate),
GetChangedDataFromInventory(mLastSynchDate));
break;
default:
break;
}
From The Daily WTF … http://thedailywtf.com/Articles/CodeThatDocumentsItselfSoWellItDoesNotNeedComments.aspx
By default, the MySQLdb module to access a MySQL database returns the data as an integer indexed array. Sometimes this is not desirable and an associative array is preferred, such as the mysql_fetch_assoc function in PHP. In addition, we will be using the pprint module which is similar PHP’s print_r
Here is the Python equivalent:
import MySQLdb import pprint # connect to the database here db = MySQLdb.connect(...) c = db.cursor(cursorclass=MySQLdb.cursors.DictCursor) query = "SELECT `name`, `address` FROM `table`" c.execute(query) rows = c.fetchall() c.close() pprint.pprint(rows) # i.e. print_r($rows)
Hope that helps someone.
The following bit of code goes in your .htaccess file and forces users to use your sub-domain as opposed to your sub-folder. In example, it forces users to use example.spechal.com and does not allow them to use spechal.com/example
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?spechal\.com
RewriteRule (.*) http://example.spechal.com/$1 [L]
So you’ve forgotten your MySQL root password have you? As long as you have command line access to the MySQL server, never fear! Execute the following bit of code from your MySQL bin directory, replacing YOURPASSWORD with your new password.
mysqladmin -u root password YOURPASSWORD
Easy as pie!
The following bit of code, which requires the win32api, simulates a mouse click using Python under the Windows OS.
import win32api, win32con
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
click(100, 100) # simulate mouse click at 100px, 100px
Here is some example code to connect to an FTP server and run the commands that follow.
@echo on %windir%\system32\ftp.exe -n -s:"%~f0" server.com goto done user myusername mypassword cd /home/directory/public_html ls -al quit :done pause
The key to this working are the following:
The -n switch allows you to not be prompted for a username upon connection.
The -s:”%~f0″ says to use the rest of the file as the commands to execute
The goto command is not a valid FTP command, so the FTP server ignores it.
So you have the script using the Windows FTP utility to connect to a server and a routine running your commands. You can even extend off of this.
20
Python Print Screen and Save Image in Windows
0 Comments | Posted by Spechal in Python, Windows
So you need to do a “Print Screen” and save the image in the clipboard huh? I had that exact need too. Let me save you a few hours of trouble and tell you that the win32clipboard does not yet have the ability to return the contents of the clipboard when the contents are BITMAP, despite the CF_BITMAP constant.
How do you do it then? I was wondering the same thing. Behold, PIL. PIL, the Python Image Library, saved me from a massive headache.
Here is the code to take a screen shot and save it. You will need the win32api and PIL libraries.
import win32api, win32con, ImageGrab
win32api.keybd_event(win32con.VK_SNAPSHOT, 1)
im = ImageGrab.grabclipboard()
im.save("screenshot.jpg", "JPEG")
Now wasn’t that easy!
There is an interesting article over at BillShrink.com about how your Internet Service Provider is likely to be ripping you off or even invading your privacy.
It’s tough to watch TV for more than ten minutes without being begged to switch Internet Service Providers. Indeed, competition for your ISP dollars is so fierce that we often see back to back commercials for different companies that provide nearly identical services. And if you believe the marketing, every ISP offers “blazing fast” speeds, “award-winning” customer service and just about everything short of eternal youth for “only $39.95 per month.” Naturally, such high and mighty promises are cause for some skepticism about what you actually receive. Today we shine the spotlight on 9 ways ISPs do and have screwed customers over, in spite of their bold claims and hefty fees.
Read the full article at http://www.billshrink.com/blog/9-ways-isps-screw-you/
It was only a matter of time before someone capitalized on President Obama calling Kanye West a Douche.
#
# Abstract Random Snow Art
# Copyright 2009 Travis Crowder
# travis.crowder@spechal.com
# Published under the MIT License
#
import pygame, sys, random
from pygame.color import THECOLORS
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([0,0,0])
for i in range(1, 2500):
top = random.randint(2, 478)
left = random.randint(2, 638)
color_name = random.choice(THECOLORS.keys())
color = THECOLORS[color_name]
pygame.draw.rect(screen, color, [left, top, 1, 1], 1)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()

