-
-
Save vuquangtam/a80364f5b755dcf06fb4cb93becba369 to your computer and use it in GitHub Desktop.
vagrant cheatsheet
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
a80364f... 07/12/16 23:57 public vagrant cheatsheet | |
a8f540d... 07/10/16 00:34 public Vagrant Cheat Sheet |
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
# setup vagrant | |
gem install vagrant | |
vagrant box add lucid32 http://files.vagrantup.com/lucid32.box | |
mkdir my_vagrant_test | |
cd my_vagrant_test | |
vagrant init lucid32 | |
vim Vagrantfile | |
vagrant up | |
vagrant ssh | |
# inside virtual machine | |
whoami | |
cd /vagrant | |
ruby -v | |
sudo apt-get update | |
sudo apt-get install build-essential zlib1g-dev curl git-core sqlite3 libsqlite3-dev | |
# vagrant commands | |
vagrant reload | |
vagrant status | |
vagrant suspend | |
vagrant resume | |
vagrant halt | |
vagrant up | |
vagrant package | |
vagrant destroy |
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
from PyQt4.QtCore import (QTime, QTimer, Qt, SIGNAL, QObject) | |
from PyQt4.QtGui import (QApplication, QLabel, QFont) | |
from pymouse import PyMouseEvent | |
import subprocess | |
import sys | |
import threading | |
from textblob import TextBlob | |
def getSelection(): | |
selection = subprocess.check_output(["xsel"]) | |
return selection | |
def translate(text, language): | |
print text | |
try: | |
text = TextBlob(text) | |
result = text.translate(to=language) | |
return result.string | |
except: | |
return "Error" | |
def notify(text, kind=""): | |
if kind == "notification": | |
subprocess.call(["notify-send", text]) | |
else: | |
subprocess.call(["zenity", "--info", "--title='Translate'", "--text", text]) | |
class Clicktranslate(PyMouseEvent, QObject): | |
def __init__(self): | |
PyMouseEvent.__init__(self) | |
QObject.__init__(self) | |
self.oldSel = "" | |
def click(self, x, y, button, press): | |
print self.oldSel | |
if button == 1: | |
text = getSelection() | |
#print text | |
if text and text != self.oldSel: | |
self.oldSel = text | |
result = translate(text, "vi") | |
#print result | |
self.emit(SIGNAL("translate"), (text + "<br>--------------<br>" + result, (x, y))) | |
#self.showLabel(text + "\n" +result) | |
#notify(text + "\n" + str(result)) | |
else: # Exit if any other mouse button used | |
self.stop() | |
class App(QApplication): | |
def __init__(self, *args): | |
QApplication.__init__(self, *args) | |
self.translate = Clicktranslate() | |
self.messageStyle = "<font color=green size=3><b>%s</b></font>" | |
self.label = QLabel() | |
self.label.setWordWrap(True); | |
self.label.setWindowFlags(Qt.ToolTip) | |
self.label.mousePressEvent = self.hideLabel | |
self.connect(self.translate, SIGNAL("translate"), self.showLabel) | |
def showLabel(self, data=("Translate...",(300, 300))): | |
self.label.setText(self.messageStyle % data[0]) | |
self.label.adjustSize() | |
self.label.move(*data[1]) | |
self.label.show() | |
def hideLabel(self, *args): | |
self.label.hide() | |
def exec_(self): | |
threading.Thread(target=self.translate.run).start() | |
QApplication.exec_() | |
app = App(sys.argv) | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment