Skip to content

Instantly share code, notes, and snippets.

View euccas's full-sized avatar

Euccas Chen euccas

View GitHub Profile
@euccas
euccas / count_email_org_db.py
Last active June 8, 2020 02:08
Use a database to count the emails by orgnizations
import sqlite3
conn = sqlite3.connect('emaildb.sqlite') # create a database is not exist
cur = conn.cursor()
cur.execute('''
DROP TABLE IF EXISTS Counts''') # three quotes support multiple lines without \n
cur.execute('''
CREATE TABLE Counts (org TEXT, count INTEGER)''')
@euccas
euccas / image_hover_overlay.html
Last active June 8, 2020 02:09
Add an overlay effect on a link (image).Example: http://carmentang.co/
<a class="post-overlay" href="http://carmentang.co/callahan-realty-group/" rel="bookmark" title="Callahan Realty Group">
<p class="view">View →</p>
</a>
.posts .post .post-overlay, .post-navigation a, .post-navigation a p {
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
@euccas
euccas / nocopy.css
Last active June 8, 2020 02:09
Doesn't allow using right button to select and copy
_
@euccas
euccas / create_view_air.sql
Last active June 8, 2020 02:09
create_a_view_for_air
CREATE VIEW air_a630_g3_latest_compiler_release AS SELECT * FROM air_promote_records WHERE project = 'a630' AND air_group = 3 AND component = 'compiler' AND status_info = 'REL_DONE' AND air_promote_vid > (SELECT MAX(air_promote_vid) FROM air_promote_records WHERE project = 'a630' AND air_group = 3 AND component = 'compiler' AND status_info = 'REL_USED' ) ORDER BY air_promote_vid ASC LIMIT 1
@euccas
euccas / get_dir_names.rb
Last active June 8, 2020 02:10
Get all directory names in a root directory
if @env_os == 'windows'
@scandir = self.scandir.gsub(/\\/, '/')
else
@scandir = self.scandir
end
all_full_rels = Dir["#{@scandir}/*"]
all_rels = []
all_full_rels.each do |frel|
if is_dir_exist(frel)
t_rel = File.basename(frel).gsub(/\/$/, '')
@euccas
euccas / count_hour_distrubution.py
Last active June 8, 2020 02:10
Write a program to read through the mbox-short.txt and figure out the distribution by hour of the day for each of the messages. You can pull the hour out from the 'From ' line by finding the time and then splitting the string a second time using a co
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
hours = dict()
for line in handle.readlines():
if line.startswith('From '):
h = line.split(' ')[6].split(':')[0]
hours[h] = hours.get(h, 0) + 1
@euccas
euccas / count_max_email.py
Last active June 8, 2020 02:10
Write a program to read through the mbox-short.txt and figure out who has the sent the greatest number of mail messages. The program looks for 'From ' lines and takes the second word of those lines as the person who sent the mail. The program creates
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
email = dict()
for line in handle.readlines():
if line.startswith('From '):
addr = line.split(' ')[1]
email[addr] = email.get(addr, 0) + 1
@euccas
euccas / countemail.py
Last active June 8, 2020 02:11
Count email in a file
fname = raw_input("Enter file name: ")
if len(fname) < 1 : fname = "mbox-short.txt"
fh = open(fname)
count = 0
for line in fh.readlines():
if line.startswith('From '):
print line.split(' ')[1]
count += 1
@euccas
euccas / divide_group.rb
Last active June 8, 2020 02:00
divide tests into groups
test_num = test_list.length
group_num = test_num / group_length
if test_num % group_length != 0
group_num += 1
end
@euccas
euccas / create_hash_of_hash.rb
Last active June 8, 2020 00:13
create hash of hash
test_info = Hash.new do |hash, key|
hash[key] = Hash.new
end