This file contains 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
require 'net/http' | |
require 'nokogiri' | |
#you need Nokogiri for this to work: gem install 'nokogiri' | |
#fetch html if not cached | |
html_cache_file = 'blackjack-chart.html' | |
if File.exist? html_cache_file | |
html = File.read(html_cache_file) | |
else |
This file contains 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
var page = require('webpage').create(); | |
page.open('http://davidgallmeier.com', function() { | |
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() { | |
var results = page.evaluate(function() { | |
var firstlinktext = $('a.post-link:first'). | |
text(). | |
toString(); | |
var firstlinkhref = $('a.post-link'). | |
map(function () { | |
return $( this ).attr('href'); |
This file contains 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
var labelsPage = Enumerable | |
.Range(0, 5) | |
.Select(pageAttempt => | |
{ | |
Thread.Sleep(2500 * pageAttempt * pageAttempt); | |
try | |
{ | |
var labelsAwql = "select LabelId,LabelName,LabelStatus limit 0,100"; | |
var attemptedlabelsPage = Config.LabelService.query(labelsAwql); |
This file contains 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
public static List<Label> GetLabels() | |
{ | |
/* | |
* use linq's lazy loading feature to enumerate an unlimited number of page requests. so i created AggregateUntil() to | |
* take in a Func() which will inform when to stop iterating - in this case, we want to stop after the entries count | |
* exceeds the totalNumEntries value, which Google Adwords returns from the first query | |
*/ | |
var labels = Enumerable | |
.Range(0, Int32.MaxValue) //range generates a list of integers, from 1 to practically infinity | |
.AggregateUntil( |
This file contains 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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var grabby = new Grabby(); | |
string output = grabby.Grab("http://www.dotnetnerd.dk/cv"); | |
Console.WriteLine(output); | |
File.WriteAllText("c:\\test.html", output); | |
} |
This file contains 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
using (var reportResponse = reportRequest.GetResponse()) | |
using (var reportReader = new StreamReader(reportResponse.Stream)) | |
using (var csv = new CsvReader(reportReader)) | |
{ | |
var records = csv | |
.GetRecords<dynamic>() | |
.Select(record => | |
{ | |
var recordDictionary = new RouteValueDictionary(record); | |
var newKeywordStat = new KeywordPerformanceStat() { |
This file contains 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
public static TAccumulate AggregateUntil<TSource, TAccumulate>(this IEnumerable<TSource> source, | |
TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate,bool> untilFunc) | |
{ | |
if (source == null) | |
{ | |
throw new ArgumentNullException(nameof(source)); | |
} | |
if (func == null) | |
{ |
This file contains 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
private static List<CriterionBidLandscape> GetCriterionBidLandscapes(DataService dataService, string awql) | |
{ | |
var bidLandscapes = Enumerable | |
.Range(0, Int32.MaxValue) | |
.AggregateUntil( | |
new CriterionBidLandscapePage() | |
{ | |
entries = new CriterionBidLandscape[] { }, | |
totalNumEntries = 0, | |
}, |
This file contains 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
public static void ImportPricingFile() | |
{ | |
using (var streamReader = new StreamReader(@"C:\Users\d.gallmeier\gits\daytoday\20180308\pricingFile.csv")) | |
using (var csv = new CsvReader(streamReader)) | |
using (var db = new SqlConnection(Config.AthenaConnectionString)) | |
{ | |
var pricingLines = csv | |
.GetRecords<dynamic>() | |
.Select(record => | |
{ |
This file contains 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
var apolloUpdateAdjustment = new Apollo.UpdateAdjustment(); | |
apolloUpdateAdjustment.itemid = Convert.ToInt64(record["ItemID"].ToString()); | |
apolloUpdateAdjustment.reason_for_update = record["Reason For Update"].ToString(); | |
apolloUpdateAdjustment.release_date = record["Release Date"].ToString(); | |
apolloUpdateAdjustment.prosales = record["ProSales"].ToString(); | |
apolloUpdateAdjustment.supply = record["SUPPLY"].ToString(); |
OlderNewer