Skip to content

Instantly share code, notes, and snippets.

@lewisou
lewisou / gist:86baa9a731bf2bb9d5af
Created June 19, 2015 05:02
Source code of the server side
// Search the record in the database by the file name
recordInDB, found := search(local.FilePath)
var compareRs int // The resule, which one to use, client side version or server side version
var execRs bool // If the operation is failed due to concurrency, so the client side can re do the request again
var newVersion int64 // Tell the client side the result of new version
// If the file previously exists
if found {
// The compare logic to find out who wins (client or server)
@lewisou
lewisou / gist:df7aa67b85e66e843b84
Created June 19, 2015 04:40
Source Code of the client side program
usr, err := user.Current() // Get the operating system user.
if err != nil {
log.Fatal( err )
} else {
monitorFolder := path.Join(usr.HomeDir, monitorFolderName) // A particular folder in the home directory.
// Make sure the folder exists
if ensureFolder(monitorFolder) {
// fileStore is an object that caches the folder status in memory
@lewisou
lewisou / gist:7701683
Created November 29, 2013 04:47
a try
Feature: Create a new check
Create a new check with sample data.
Sample data is a subset of real data at a particular time point and should fullfill bellow constrants:
location: should include status inactive and active.
item: should include status inactive, active.
item group: should include type NP and not NP. (but this time, we don't find NP quantities in whole real data)
Inventory (frozen quantity): should be fall in all categories above.
Real data exported on 2013/11/28, (don't find NP quantities...) and we generate sample data in R.
@lewisou
lewisou / examples.hs
Created March 4, 2013 02:21
Haskel Function Pattern Match Syntax Examples
import Data.List -- sortBy
myLength :: [a] -> Int
myLength [] = 0
myLength (x:xs) = 1 + (myLength xs)
meanOfList [] = 0
meanOfList xs = (fromIntegral (listSum xs)) / (fromIntegral (myLength xs))
where listSum [] = 0
listSum (e:es) = e + (listSum es)
@lewisou
lewisou / fetch_feed.rb
Created April 28, 2012 02:39
An example to fetch feeds.
# Add this line into your Gemfile.
gem 'feedzirra', '~> 0.0.24'
# Fetch and Parse, we take javascript weekly as an example.
feed = Feedzirra::Feed.fetch_and_parse('http://javascriptweekly.com/rss')
# Basic information of the feed.
feed.title
feed.url
feed.feed_url
@lewisou
lewisou / scrape_images.rb
Created April 28, 2012 01:59
Scrape Images from a web page.
# Add the line to the Gemfile of your application.
gem 'rest-client', '~> 1.6.7'
# In your code, we take website www.designbombs.com as an example to scrape all images.
rs = []
RestClient.get('http://www.designbombs.com/') do |response, _req, _res|
if response.code == 200
response.to_s.scan(/<img[^>]+src\s*=\s*['"]([^'"]+)['"][^>]*>/) do |url|
rs << url
end
@lewisou
lewisou / placeholder_fix.js
Created January 18, 2012 04:30
Deal with placeholder without browser support
function elementSupportsAttribute(element, attribute) {
var test = document.createElement(element);
if (attribute in test) {
return true;
} else {
return false;
}
};
$(document).ready(function(){