Skip to content

Instantly share code, notes, and snippets.

@sanny-io
Created December 11, 2016 08:32
Show Gist options
  • Select an option

  • Save sanny-io/f84872c459fea68f3ed3d46e1fc32620 to your computer and use it in GitHub Desktop.

Select an option

Save sanny-io/f84872c459fea68f3ed3d46e1fc32620 to your computer and use it in GitHub Desktop.
Sublime plugin for this thingy https://www.securegmod.com/minifier/
import sublime
import sublime_plugin
import urllib
endpoint = "https://www.securegmod.com/api/minify"
class sgminifyCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if not region.empty():
code = self.view.substr(region)
self.view.replace(edit, region, self.minify(code))
def minify(self, code):
hdrs = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',}
req = urllib.request.Request(endpoint, headers=hdrs)
req.data = str.encode(urllib.parse.urlencode({'body': code}))
response = urllib.request.urlopen(req)
return bytes.decode(response.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment