Skip to content

Instantly share code, notes, and snippets.

@antun
antun / lctime
Last active January 9, 2024 22:08
Converts time from seconds since 1970 to a human readable date
#!/usr/bin/env python
import sys, time
if __name__ == '__main__':
args = sys.argv[1:]
for arg in args:
print(time.ctime( int(arg) ))
@antun
antun / xmlunescape
Last active July 15, 2022 22:40
XML unescapes a string
#!/usr/bin/env python
import sys, xml.sax.saxutils
if __name__ == '__main__':
args = sys.argv[1:]
for arg in args:
print xml.sax.saxutils.unescape( arg )
@antun
antun / xmlescape
Last active July 15, 2022 22:41
XML-encodes a string
#!/usr/bin/env python
import sys, xml.sax.saxutils
if __name__ == '__main__':
args = sys.argv[1:]
for arg in args:
print xml.sax.saxutils.escape( arg )
@antun
antun / urldecode
Last active July 15, 2022 22:35
URL unencodes (decodes) a string passed via command line
#!/usr/bin/env python
import sys, urllib
if __name__ == '__main__':
args = sys.argv[1:]
for arg in args:
print urllib.unquote( arg )
@antun
antun / urlencode
Last active July 15, 2022 22:36
URL encodes a string passed via the command line.
#!/usr/bin/env python
import sys, urllib
if __name__ == '__main__':
args = sys.argv[1:]
for arg in args:
print urllib.quote( arg )
@antun
antun / migrate_users_to_paperclip.rb
Created October 2, 2012 04:44
Rails migration for switching from file_column to paperclip.
require 'fileutils'
class MigrateUsersToPaperclip < ActiveRecord::Migration
def up
# Rename the old "mugshot" column to "old_file_name", since User.mugshot will now try to do Paperclip stuff
rename_column :users, :mugshot, :old_file_name
# Rename asset directories to pluralize
File.rename("public/system/user","public/system/users")