This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function elementSupportsAttribute(element, attribute) { | |
var test = document.createElement(element); | |
if (attribute in test) { | |
return true; | |
} else { | |
return false; | |
} | |
}; | |
$(document).ready(function(){ |