Skip to content

Instantly share code, notes, and snippets.

View euccas's full-sized avatar

Euccas Chen euccas

View GitHub Profile
@euccas
euccas / connect_list_items.py
Last active June 8, 2020 02:07
Generate a string connecting items of a given list. The string should look like: a and b a, b and c Being strict on the separator and "and".
item_names = mydict["items"].split()
if len(item_names) > 1:
item_names[-1] = "and " + dv_tiers[-1]
sep = ", " if len(item_names) > 2 else " "
namstr = sep.join(item_names)
print namestr # a, b and c
@euccas
euccas / jenkins_copy_jobs_in_view.groovy
Last active June 8, 2020 02:08
Copy all jobs in a view
import hudson.model.*
def str_view = "AIR_Project_A630"
def str_search = "air_a630"
def str_replace = "air_a630v1"
def view = Hudson.instance.getView(str_view)
//copy all projects of a view
for(item in view.getItems())
@euccas
euccas / test_jsonb.rb
Last active June 8, 2020 02:08
postgresql JSONB
require 'pg'
require 'json'
def db_connect(host, dbname, user, password)
begin
conn = PGconn.connect(host, 5436, '', '', dbname, user, password)
rescue
puts "Failed to connect to database #{dbname} on #{host}"
end
return conn
@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