Skip to content

Instantly share code, notes, and snippets.

@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")
@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 / 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 / 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 / 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 / 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 / lzx.vim
Created February 23, 2013 00:30
OpenLaszlo LZX Sytax file
so $VIMRUNTIME/syntax/xml.vim
let b:current_syntax = "lzx"
syn region lzxScript start=+<script>+ end=+</script>+ extend containedin=xmlRegion contains=lzxCData,xmlTag,xmlEqual,xmlEndTag fold keepend
syn region lzxMethod start=+<method+ end=+</method>+ extend containedin=xmlRegion contains=lzxCData,xmlTag,xmlEqual,xmlEndTag fold keepend
syn region lzxEventHandler start=+\Won\w\{-}="+ end=+"+ containedin=xmlTag contains=xmlAttrib,xmlEqual,lzxScriptAttribute,lzxAttributeQuote contained keepend
syn region lzxScriptAttribute matchgroup=lzxAttributeQuote start=+="+ end=+"+ contained
@antun
antun / csv2xlsx.py
Last active August 29, 2015 13:58 — forked from konrad/csv2xlsx.py
#!/usr/bin/env python
"""
FUNCTION: Converts a CSV (tab delimited) file to an Excel xlsx file.
Copyright (c) 2012, Konrad Foerstner <konrad@foerstner.org>
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all
copies.
@antun
antun / jsonp2json
Last active December 20, 2018 18:58
#!/usr/bin/env python
import sys
rawinput = sys.stdin.read()
output = rawinput[ rawinput.index("(") + 1 : rawinput.rindex(")") ]
print(output)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import csv
import sys
import codecs
import pprint
from openpyxl import load_workbook