Skip to content

Instantly share code, notes, and snippets.

@tienhv
tienhv / dropbox.txt
Created September 30, 2015 08:53
Dropbox CLI
Prerequisites
Architecture x86 (32-bit) or x86_64 (64-bit)
wget
vi (text editor)
Python 2.x
a web browser (on a PC you have access to)
Setup process
Install the latest dropbox linux distro
@tienhv
tienhv / lxc.md
Created September 15, 2015 09:24
lxc

Exposing a directory on the host machine to an LXC container

  1. Log into the container and create an empty directory, this will be the mount point
  2. Log out and stop the container.
  3. Open to your container's config file
    • For regular LXC containers: /var/lib/lxc/mycontainer/config
    • For unprivileged LXC containers: $HOME/.local/share/lxc/mycontainer/config
  4. Add a new line above the lxc.mount directive, that follows the format below. Substitute proper paths as necessary:
    • lxc.mount.entry = /path/to/folder/on/host /path/to/mount/point none bind 0 0
  • Both of these paths are relative to the host machine.
@tienhv
tienhv / web_browser.py
Created September 5, 2015 14:39
web browser pyqt4, simple with back, refresh and forward button
#!/usr/bin/env python
"A web browser that will never exceed 128 lines of code. (not counting blanks)"
import sys
from PyQt4 import QtGui,QtCore,QtWebKit
class MainWindow(QtGui.QMainWindow):
def __init__(self, url):
QtGui.QMainWindow.__init__(self)
self.sb=self.statusBar()
#!/usr/bin/python
# -*- coding: utf-8 -*-
_ = (255, lambda V, B, c: (c and Y(V * V + B, B, c - 1) if abs(V)
< 6 else (2 + c - 4 * abs(V) ** -0.4) / i))
(v, x) = (1500, 1000)
C = range(v * x)
import struct
P = struct.pack
(M, j) = ('<QIIHHHH', open('M.bmp', 'wb').write)
for X in j('BM' + P(
@tienhv
tienhv / google-search.py
Created July 21, 2015 15:12
search google by selenium
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class Test(unittest.TestCase):
@tienhv
tienhv / gmail-login.py
Created July 21, 2015 15:11
login gmail selenium
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class Gmail(unittest.TestCase):
@tienhv
tienhv / log.py
Created July 19, 2015 09:22
logging template, with function name,etc.
print 'hello'
import logging
#logging.basicConfig(level=logging.DEBUG)
#logger = logging.getLogger(__name__)
#handler = logging.FileHandler('hello.log')
#formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#handler.setFormatter(formatter)
#logger.addHandler(handler)
logger = logging.getLogger(__name__)
from setuptools import setup
setup(
name='tail',
version='1.0',
py_modules=['tail'],
entry_points='''
[console_scripts]
tail=tail:tail2
head=tail:head
@tienhv
tienhv / tail.py
Last active August 29, 2015 14:24 — forked from amitsaha/tail.py
'''
Basic tail command implementation
Usage:
tail.py filename numlines
'''
import sys
import linecache
@tienhv
tienhv / demo.txt
Created June 24, 2015 13:58
a sample gist
Hey GitHub