on idle
tell application "System Events"
tell current location of network preferences
set myConnection to the service "Your VPN Name"
if myConnection is not null then
if current configuration of myConnection is not connected then
connect myConnection
end if
end if
end tell
return 120
end tell
end idle
将“Your VPN Name"换成自己的VPN名称,勾选“Stay Open”选项框,保存一下。将保存的文件拖到任务栏中,右键点击Options->Open at Login。重新登录用户,搞定。以上代码将以每2分钟一次间隔检测VPN链接状态,可以自行修改120为其他数值(单位为秒)。
There is a fun website for Python beginners. Python Challenge. I will post some code I used to solve the problems.
0. 2 to the power of 38.
1. Translate the string by replace every letter with letter position 2 after. Notice the 'z' should translates to 'b'.
text = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
result = '';
for c in text:
if 'a' <= c <= 'z':
result += chr((ord(c) - ord('a') + 2) % 26 + ord('a'))
elif 'A' <= c <= 'Z':
result += chr((ord(c) - ord('A') + 2) % 26 + ord('A'))
else:
result += c
print result
2. Find the hidden word from string
text='.. text from html source..'
chList = {}
for ch in text:
if ch in chList.keys():
chList[ch] = chList[ch] + 1
else:
chList[ch] = 1
print chList #a,e,i,l,q,u,t,y = 1
for ch in text:
if ch in 'aeilquty':
print ch #equality
3. Find the hidden word by using regex
text='.. text from html source..'
pattern = "[a-z][A-Z]{3}[a-z][A-Z]{3}[a-z]"
m = re.findall(pattern, text)
result = ""
for str in m:
result += str[4]
print result
4. Send http request and parse the returning string
import urllib2
import re
link = urllib2.urlopen("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345")
while link.getcode() == 200:
#get another nothing code
text = link.read()
print text
pattern = "the next nothing is [0-9]+"
m = re.search(pattern,text)
if m:
tmp = m.group()
pattern2 = "[0-9]+"
m = re.search(pattern2, tmp)
code = m.group()
else:
code = str(int(code) / 2)
url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + code
link = urllib2.urlopen(url)
5. 'Peak Hell' implies 'pickle', format the string, you will see the result
from __future__ import print_function
import pickle
import urllib2
import sys
text = urllib2.urlopen("http://www.pythonchallenge.com/pc/def/banner.p").read()
result = pickle.loads(text)
for arr in result:
for tuple in arr:
print(tuple[0]*tuple[1], end='')
print('\n')
Jar Hell is the situation when you have the different incompatible versions of library existed in your classpath simultaneously. For example, you have a project that depends on library A version 2.0, and you also need a third party library B which depends on library A version 1.0, then the library version 1.0 and version 2.0 will all be included in your classpath, it will cause some problems because machine doesn't know which version to choose in the right place.
I just encountered this problem in my recent project, so I did a lot of research of it. However, in theory, there's no best way to resolve it. So I list all the possible solutions here:
1. Avoid
First of all, you should consider this problem before you proceed. Find all the dependencies that your library will use, and make sure all library versions are compatible. It will save your a lot of troubles!
2. Find a transition version that works for both sides
If it already happened, then you should consider finding a transition version. Library changes gradually, so you may be luck to find a right version.
3. Use Jarjar
If your project won't involve any shared interface between the incompatible versions, then you should definitely try Jarjar, a jar wrap tool that can rename the embedded class files. It works like a charm, will do a lot of work with your imagination. There's a blog talking about it.
However, there are one limitation you should know:
If the incompatible versions of library have different interfaces, and these interfaces will be used in your project, then you are no lucky because even they have the some interface name, they are in different packages(jarjar changed the package name), so they are definitely different interfaces, you can't assign instances directly.
But there is also a solution to this case, which is to write adapter classes to wrap one interface to the other, it works in some situations.
4. Modify library source code
If you have access to the library source code, you could also change the incompatible code by yourself and wrap it as a customized jar to fulfill your need. It works well when the difference between versions is not that much.
5. Access Rule & Maven solution
I didn't dig into it too much, but it seems workable to some situation. The Access Rule (see this article) can forbid some classes from using. The Maven also have similar access rules.
I was doing some research about how to use OpenLink Virtuoso in my own project. First I want to try something basic, so I start with Triple-store and SPARQL query. This article is about how to transform Non-RDF file to RDF, insert RDF into Virtuoso Triple-store, and then search the result by using SPARQL.
Brief introduction
Transform Non-RDF to RDF
There are a lot of tools can be used to transform Non-RDF to RDF. I will use the GRefine RDF Extension. Here is a tutorial video.
What is Virtuoso
OpenLink Virtuoso is an ambitious software, it provides Web, File, and Database server functionality alongside Native XML Storage, and Universal Data Access Middleware. And, yes, it has implementation of Triple-store to store RDFs.
Let's focus on the Virtuoso triple-store.
Virtuoso triple-store is built atop of traditional RDBMS( See implementation here ). Triples are stored in a table called RDF_QUAD(See table below). Every RDF is composed by triples which will be inserted into RDF_QUAD table.
Triple-store uses Graph to group triples. There is a IRI, similar to URI, to identify every Graph. So when you try to insert data into triple-store, you should specify the IRI of the Graph.
To search triples in a Graph, you should first give the IRI of the Graph, then use Virtuoso SPARQL (which is implemented atop of SQL by Virtuoso) to query the triple-store.
My experiment
My goal is to combine air quality data with disease data using Virtuoso triple-store engine. I found the data source on the AirNow and CDC Database.
Step1: Convert Non-RDF to RDF
First I imported data into GRefine RDF Extension. Of course, you should trim some irrelevant date before importing. After this step, you should see the similar results below.
Then I started to create RDF skeleton, select RDF->Edit RDF Skeleton. If you don't know how to do this, watch the tutorial video above.
You can see the RDF skeleton graph below.
The result should be like this:
Next is to export the RDF file, choose Export->RDF as XML or Export->RDF as Turtle. Done!
Step 2: Insert RDF into Virtuoso Triple-store
Before start, you should install the Virtuoso, I recommend you to use Virtuoso Open-source Edition. Try to build from source code to get the most stable version(which was 6.1.8 when wrote this blog).
Then connect Virtuoso by using command line tool: isql. The default isql location should be at /usr/local/bin/isql .
If you want to insert TTL(TURTLE file), use command below:
ps #show process ps -l #Display information associated with the following keywords: uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan, state=S, paddr=ADDR, tty, time, and command=CMD ps aux | grep <keyword> #show details of process
Kill
kill [signal] PID #kill specified process using pid, most used is '-9' to kill process.
kill -l #display all the [signal]s kill `ps | grep <keyword> | awk '{print $1}'` #kill process by <keyword>
TOP
top #display all process
top -user <user> #display <user>'s process
top -pid <pid> #display process by given <pid>
service
service <service-name> status #show service status(running or stopped)
useradd -G <group-name> <username> #add user to non-existed group useradd -g <group-name> <username> #add user to primary group usermod -a -G <group-name> <username> #add a existing user to existing group usermod -g <group-name> <username> #change user's primary group to <group-name> passwd <username> #setup password for user id <username> #show user information
# wget http://mirror.symnds.com/software/Apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz # tar -zxvf apache-maven-3.1.1-bin.tar.gz # mkdir -p /usr/lib/maven # mv apache-maven-3.1.1 /usr/lib/maven # vi ~/.bash_profile Add Scripts before export PATH: PATH=$PATH:/usr/lib/maven/bin
13. Get a copy of the repository for Storm on YARN from GitHub