text 使用node-simplecrawler在nodejs中抓取facebook

使用node-simplecrawler在nodejs中抓取facebook

gistfile1.txt
var Crawler = require("simplecrawler");
var Url = require("url");

var target = "https://graph.facebook.com/ledzeppelin/feed?access_token=1597581200507009%7Ce749be55ea86249f92ae56b081c37b38&fields=from%2Cmessage%2Ccreated_time%2Ctype%2Clink%2Ccomments.summary(true)%2Clikes.summary(true)%2Cshares&since=2016-07-11&until=2016-07-14&limit=10";
var url = Url.parse(target);

var crawler = new Crawler(url.host);
crawler.initialPath = url.path;
crawler.initialPort = 443;
crawler.initialProtocol = "https";

crawler.maxConcurrency = 1;
crawler.maxDepth = 2;
crawler.stripQuerystring = false;
crawler.decodeResponses = true;
crawler.supportedMimeTypes.push(/^application\/json/i);
 
crawler.on("fetchcomplete", function(queueItem, buffer, response) {
    console.log("Completed fetching resource:", queueItem.url);
    node.send({payload: "Completed fetching resource: " + queueItem.url});
    node.send({payload: buffer});
});

crawler.on("fetcherror", function(queueItem, response) {
    console.log("Error fetching resource:", queueItem.url);
    //console.log(queueItem);
    node.send({payload: {"error" : queueItem}});
});

crawler.discoverResources = function(buffer, queueItem) {
    try {
        var data = JSON.parse(buffer);
        if (data.paging && data.paging.next) {
            return [data.paging.next];
        }
    }
    catch (e) {
        console.log(e);
    }
    return [];
};


crawler.start();
console.log("start crawling...");

text grep例子

grep例子

grep only saerch c source
grep -inIr --include="*.c" "PATTERN" 

text 节点宁静

节点宁静

node-restful
https://medium.freecodecamp.org/build-restful-api-with-authentication-under-5-minutes-using-loopback-by-expressjs-no-programming-31231b8472ca

text 通过资产获取的位图

通过资产获取的位图

getBitmapFromAsset
   private Bitmap getBitmapFromAsset(Context context, String strName) {
        AssetManager assetManager = context.getAssets();
        InputStream istr;
        Bitmap bitmap = null;
        try {
            istr = assetManager.open(strName);
            bitmap = BitmapFactory.decodeStream(istr);
        } catch (IOException e) {
            return null;
        }
        return bitmap;
    }

text 将EpochTime隐藏到日期时间并将日期时间转换为EpochTime

covert EpochTime to Datetime and covert Datetime to EpochTime
 /// <summary>
/// Converts the given date value to epoch time.
/// </summary>
public static long ToEpochTime(this DateTime dateTime)
{
    var date = dateTime.ToUniversalTime();
    var ticks = date.Ticks - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks;
    var ts = ticks / TimeSpan.TicksPerSecond;
    return ts;
}

/// <summary>
/// Converts the given date value to epoch time.
/// </summary>
public static long ToEpochTime(this DateTimeOffset dateTime)
{
    var date = dateTime.ToUniversalTime();
    var ticks = date.Ticks - new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).Ticks;
    var ts = ticks / TimeSpan.TicksPerSecond;
    return ts;
}

/// <summary>
/// Converts the given epoch time to a <see cref="DateTime"/> with <see cref="DateTimeKind.Utc"/> kind.
/// </summary>
public static DateTime ToDateTimeFromEpoch(this long intDate)
{
    var timeInTicks = intDate * TimeSpan.TicksPerSecond;
    return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddTicks(timeInTicks);
}

/// <summary>
/// Converts the given epoch time to a UTC <see cref="DateTimeOffset"/>.
/// </summary>
public static DateTimeOffset ToDateTimeOffsetFromEpoch(this long intDate)
{
    var timeInTicks = intDate * TimeSpan.TicksPerSecond;
    return new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).AddTicks(timeInTicks);
}

text 用于将JSON提要解析为RowList的代码示例

用于将JSON提要解析为RowList的代码示例

A SceneGraph JSON Feed Example.md
This example shows how to load a JSON feed into a ScenGraph RowList in Roku. It's not a complete application. This code started life as Simple_Grid_with_Details_and_Video, available here: https://blog.roku.com/developer/2016/03/03/scenegraph-tutorial/ 

The json_parser.brs file has the brightscript code to load the feed data (represented by the contents of data.json).
The data is then translated into an array of MediaItems. MediaItem is an extended ContentNode.
Then the data is structured to load into a RowList, which is represented in GridScreen.xml.

GridScreen.xml
<?xml version="1.0" encoding="utf-8" ?>

<component name="GridScreen"
    extends="Group"
    initialFocus="RowList">
    <!-- main handler -->
    <script type="text/brightscript"
        uri="pkg:/components/screens/GridScreen.brs" />
	<interface>
		<!-- Grid Content Node -->
		<field id="content"
		    type="node"
		    alias="RowList.content"
		    onChange="onContentChange" />
		<!-- Row item selection handler -->
		<field id="rowItemSelected"
		    type="intarray"
		    alwaysnotify="true"
		    alias="RowList.rowItemSelected" />
		<!-- Row item focused handler -->
		<field id="itemFocused"
		    type="intarray"
		    alias="RowList.rowItemFocused"
		    onChange="OnItemFocused" />
		<!-- Interface to focused item (Content Node) -->
		<field id="focusedContent"
		    type="node" />

	</interface>


	<children>

		<RowList id="RowList"
		    translation="[200, 300]"
		    itemSize="[1920, 225]"
            numRows="3"
		    itemSpacing="[0, 100]"
		    rowFocusAnimationStyle="fixedFocusWrap"
		    rowItemSize="[[400, 225]]"
		    rowItemSpacing="[[20, 0]]"
		    showRowLabel="true"
		    showRowCounter="false"
		    rowLabelOffset="[[20, 20]]"
		    loadingBitmapOpacity="1.0"
		    failedBitmapOpacity="1.0"
		    loadingBitmapUri="pkg:/images/gmo_logo_hd.png"
		    failedBitmapUri="pkg:/images/gmo_logo_hd.png" />

	</children>
</component>
MediaItem.xml
<?xml version="1.0" encoding="utf-8" ?>
<component name="MediaItem" extends="ContentNode">
	<interface>
		<field id="thumbnail" type="string" />
		<field id="contentType" type="string" />
		<field id="title" type="string" />
		<field id="entitlement" type="string" />
		<field id="externalAdvertiserId" type="string" />
		<field id="mpxMediaGuid" type="string" />
		<field id="mpxAccountId" type="string" />
		<field id="duration" type="float" />
		<field id="trackingData" type="assocarray" />
		<field id="category" type="string" />
		<field id="stream" type="assocarray" />
	</interface>
</component>
feed.json
{
    "$xmlns": {
        "pl1": "http://access.auth.theplatform.com/data/Account/2295898951",
        "nbcu": "http://xml.nbcuni.com/media/field"
    },
    "startIndex": 1,
    "itemsPerPage": 3,
    "entryCount": 3,
    "title": "PROD Feed for Video Assets",
    "description": "PROD Feed for Video Assets",
    "entries": [
        {
            "id": "http://data.media.theplatform.com/media/data/Media/939146307771",
            "guid": "3515752",
            "updated": 1494453617000,
            "title": "Queen of the South - There’s A New Queen In Town",
            "description": "Queen of the South premieres Thursday, June 8 at 10/9c.",
            "added": 1494285069000,
            "availableDate": 1494453600000,
            "expirationDate": 1497002400000,
            "categories": [
                {
                    "name": "Series/Queen of the South",
                    "scheme": "",
                    "label": ""
                }
            ],
            "copyright": "",
            "copyrightUrl": "",
            "keywords": "Queen of the South,Alice Braga,Adrana Barraza,Hemky Madera,James Martinez,Joaquim de Almeida",
            "ratings": [
                {
                    "scheme": "urn:mpaa",
                    "rating": "nr",
                    "subRatings": [

                    ]
                }
            ],
            "countries": [
                "GU",
                "MP",
                "PR",
                "US",
                "VI"
            ],
            "excludeCountries": false,
            "content": [
                {
                    "duration": 30.030,
                    "format": "MPEG4",
                    "height": 240,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 416
                },
                {
                    "duration": 30.030,
                    "format": "MPEG4",
                    "height": 544,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 960
                },
                {
                    "duration": 30.000,
                    "format": "MPEG4",
                    "height": 720,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 1280
                },
                {
                    "duration": 30.000,
                    "format": "MPEG4",
                    "height": 540,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 960
                },
                {
                    "duration": 30.000,
                    "format": "MPEG4",
                    "height": 1080,
                    "isDefault": true,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 1920
                },
                {
                    "duration": 30.000,
                    "format": "MPEG4",
                    "height": 360,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 640
                },
                {
                    "duration": 30.000,
                    "format": "MPEG4",
                    "height": 234,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 416
                },
                {
                    "duration": 0.000,
                    "format": "TCM",
                    "height": 0,
                    "isDefault": false,
                    "language": "",
                    "url": "http://link.theplatform.com/...",
                    "width": 0
                }
            ],
            "thumbnails": [
                {
                    "duration": 0.000,
                    "format": "JPEG",
                    "height": 1080,
                    "isDefault": false,
                    "language": "",
                    "url": "http://tve-static-usanetwork.nbcuni.com/prod/image/664/731/170508_3515752_Queen_of_the_South___Action_Packed_anvver_2.jpg",
                    "width": 1920
                }
            ],
            "pubDate": 1494283080000,
            "defaultThumbnailUrl": "http://tve-static-usanetwork.nbcuni.com/prod/image/664/731/170508_3515752_Queen_of_the_South___Action_Packed_anvver_2_800x450_939405379534.jpg",
            "provider": "USA",
            "pl1$dayPart": "Primetime",
            "pl1$entitlement": "free",
            "pl1$event": "",
            "pl1$externalAdvertiserId": "USA_ANV_3515752",
            "pl1$fullEpisode": false,
            "pl1$promo": false,
            "pl1$seasonNumber": 2,
            "pl1$shortDescription": "Queen of the South premieres Thursday, June 8 at 10/9c.",
            "pl1$shortTitle": "Queen of the South - There’s A New Queen In Town",
            "nbcu$advertisingGenre": "Drama",
            "nbcu$programmingType": "Undefined"
        },
        {
            "id": "http://data.media.theplatform.com/media/data/Media/939128899982",
            "guid": "3515747",
            "updated": 1494324030000,
            "title": "Queen of the South - All The Way Up",
            "description": "Catch the premiere of Queen of the South Thursday, June 8 at 10/9c.",
            "added": 1494283878000,
            "availableDate": 1494324000000,
            "expirationDate": 1497002400000,
            "categories": [
                {
                    "name": "Series/Queen of the South",
                    "scheme": "",
                    "label": ""
                }
            ],
            "copyright": "",
            "copyrightUrl": "",
            "keywords": "Queen of the South,Alice Braga,Adrana Barraza,Hemky Madera,James Martinez,Joaquim de Almeida",
            "ratings": [
                {
                    "scheme": "urn:mpaa",
                    "rating": "nr",
                    "subRatings": [

                    ]
                }
            ],
            "countries": [
                "GU",
                "MP",
                "PR",
                "US",
                "VI"
            ],
            "excludeCountries": false,
            "content": [
                {
                    "duration": 60.000,
                    "format": "MPEG4",
                    "height": 360,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 640
                },
                {
                    "duration": 60.061,
                    "format": "MPEG4",
                    "height": 544,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 960
                },
                {
                    "duration": 60.000,
                    "format": "MPEG4",
                    "height": 234,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 416
                },
                {
                    "duration": 60.061,
                    "format": "MPEG4",
                    "height": 240,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 416
                },
                {
                    "duration": 60.000,
                    "format": "MPEG4",
                    "height": 720,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 1280
                },
                {
                    "duration": 60.000,
                    "format": "MPEG4",
                    "height": 540,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 960
                },
                {
                    "duration": 60.000,
                    "format": "MPEG4",
                    "height": 1080,
                    "isDefault": true,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 1920
                },
                {
                    "duration": 0.000,
                    "format": "TCM",
                    "height": 0,
                    "isDefault": false,
                    "language": "",
                    "url": "http://link.theplatform.com/...",
                    "width": 0
                }
            ],
            "thumbnails": [
                {
                    "duration": 0.000,
                    "format": "JPEG",
                    "height": 1080,
                    "isDefault": false,
                    "language": "",
                    "url": "http://tve-static-usanetwork.nbcuni.com/prod/image/648/115/170508_3515747_Queen_of_the_South___All_The_Way_Up.jpg",
                    "width": 1920
                }
            ],
            "pubDate": 1494282540000,
            "defaultThumbnailUrl": "http://tve-static-usanetwork.nbcuni.com/prod/image/648/115/170508_3515747_Queen_of_the_South___All_The_Way_Up_800x450_939133507784.jpg",
            "provider": "USA",
            "pl1$dayPart": "Primetime",
            "pl1$entitlement": "free",
            "pl1$event": "",
            "pl1$externalAdvertiserId": "USA_ANV_3515747",
            "pl1$fullEpisode": false,
            "pl1$promo": false,
            "pl1$seasonNumber": 2,
            "pl1$shortDescription": "Catch the premiere of Queen of the South Thursday, June 8 at 10/9c.",
            "pl1$shortTitle": "Queen of the South - All The Way Up",
            "nbcu$advertisingGenre": "Drama",
            "nbcu$programmingType": "Undefined"
        },
        {
            "id": "http://data.media.theplatform.com/media/data/Media/914045507807",
            "guid": "3496379",
            "updated": 1494151208000,
            "title": "Big Star Little Star Interview:  Penn Jillette, Brooke Burke, Harold Perrineau",
            "description": "Meet the celebrity contestants of the hilarious new game show, BIG STAR LITTLE STAR. Check out more exclusive BIG STAR LITTLE STAR videos, galleries and more at usanetwork.com.",
            "added": 1491347776000,
            "availableDate": 1494151200000,
            "expirationDate": 1499853600000,
            "categories": [
                {
                    "name": "Series/Big Star Little Star",
                    "scheme": "",
                    "label": ""
                }
            ],
            "copyright": "",
            "copyrightUrl": "",
            "keywords": "Big Star Little Star,Cat Deeley,Corin Nelson,David George,Brian Zagorsk",
            "ratings": [
                {
                    "scheme": "urn:v-chip",
                    "rating": "tv-pg",
                    "subRatings": [

                    ]
                }
            ],
            "countries": [

            ],
            "excludeCountries": true,
            "content": [
                {
                    "duration": 63.000,
                    "format": "MPEG4",
                    "height": 1080,
                    "isDefault": true,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 1920
                },
                {
                    "duration": 63.000,
                    "format": "MPEG4",
                    "height": 720,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 1280
                },
                {
                    "duration": 63.000,
                    "format": "MPEG4",
                    "height": 360,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 640
                },
                {
                    "duration": 63.364,
                    "format": "MPEG4",
                    "height": 240,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 416
                },
                {
                    "duration": 63.000,
                    "format": "MPEG4",
                    "height": 540,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 960
                },
                {
                    "duration": 0.000,
                    "format": "TCM",
                    "height": 0,
                    "isDefault": false,
                    "language": "",
                    "url": "http://link.theplatform.com/...",
                    "width": 0
                },
                {
                    "duration": 63.000,
                    "format": "MPEG4",
                    "height": 234,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 416
                },
                {
                    "duration": 63.364,
                    "format": "MPEG4",
                    "height": 544,
                    "isDefault": false,
                    "language": "en",
                    "url": "http://link.theplatform.com/...",
                    "width": 960
                }
            ],
            "thumbnails": [
                {
                    "duration": 0.000,
                    "format": "JPEG",
                    "height": 1080,
                    "isDefault": false,
                    "language": "",
                    "url": "http://tve-static-usanetwork.nbcuni.com/prod/image/278/743/170404_3496379_Big_Star_Little_Star_Interview___Penn_Jillet.jpg",
                    "width": 1920
                }
            ],
            "pubDate": 1491341820000,
            "defaultThumbnailUrl": "http://tve-static-usanetwork.nbcuni.com/prod/image/278/743/170404_3496379_Big_Star_Little_Star_Interview___Penn_Jillet_800x450_914051139503.jpg",
            "provider": "USA",
            "pl1$dayPart": "Primetime",
            "pl1$entitlement": "free",
            "pl1$event": "",
            "pl1$externalAdvertiserId": "USA_ANV_3496379",
            "pl1$fullEpisode": false,
            "pl1$promo": false,
            "pl1$seasonNumber": 1,
            "pl1$shortDescription": "Meet the celebrity contestants of the hilarious new game show, BIG STAR LITTLE STAR. Check out more exclusive BIG STAR LITTLE STAR videos, galleries and more at usanetwork.com.",
            "pl1$shortTitle": "Big Star Little Star Interview:  Penn Jillette, Brooke Burke, Harold Perrineau",
            "nbcu$advertisingGenre": "Reality and Game Show",
            "nbcu$programmingType": "Behind the Scenes"
        }
    ]
}
parse_json.brs
sub loadContent()
  shortFormRow = GetShortForm()
  list = [
      {
          TITLE : "Short Form"
          ContentList : shortFormRow
      }
  ]
  m.contentselection = m.top.findNode("GridScreen")
  m.contentselection.content = ParseContent(list)
end sub

Function GetShortForm()
    url = CreateObject("roUrlTransfer")
    url.SetUrl("http://yourcontentprovider.com/data.json")
    rsp = url.GetToString()
    response = parseJSON(rsp)
    result = parseFeed(response)
    return result
End Function

function parseFeed(feed)
    result = []
    regex = CreateObject("roRegex", "/", "i")
    for each item in feed.entries
        asset = {}
        asset.HDPosterUrl = item.defaultThumbnailUrl
        asset.hdBackgroundImageUrl = item.defaultThumbnailUrl
        asset.streamFormat = "hls"
        asset.Categories=[]
        asset.filmstrip= item.filmstrip
        asset.thumbnail = item.defaultThumbnailUrl
        asset.title = item.title
        asset.description = item.description
        asset.releasedate = item.added
        asset.mpxmediaguid = item.guid
        asset.entitlement = item["pl1$entitlement"]
        asset.externaladvertiserid =item["pl1$externalAdvertiserId"]
        asset.duration = item.content[0].duration
        if item.ownerId <> invalid
            asset.mpxAccountId = regex.Split(item.ownerId).peek()
        else
            asset.mpxAccountId = "2304992029"
        end if
        if item.categories <> invalid AND item.categories[0] <> invalid
           asset.category=item.categories[0].name
        end if
        mediaType = "VOD Clip"
        if item["pl1$fullEpisode"] = true OR item["nbcu$fullEpisode"] = true
            mediaType = "VOD Episode"
        end if
        asset.trackingData = {}
        asset.trackingdata["tve.videoprogram"] = item.title
        asset.trackingdata["tve.videocontent"] =  mediaType
        asset.TrackingData["tve.length"] = item.content[0].duration
        asset.TrackingData["tve.season"] = "999"
        asset.TrackingData["tve.epnumber"] = "888"
        asset.TrackingData["tve.airdate"] = "2001-04-01"
        asset.stream = {url:""}
        result.push(asset)
    end for
    return result
end function

Function ParseContent(list As Object)
    RowItems = createObject("RoSGNode","ContentNode")
    for each rowAA in list
        row = createObject("RoSGNode","ContentNode")
        row.Title = rowAA.Title
        for each itemAA in rowAA.ContentList
            item = createObject("RoSGNode","MediaItem")
            ' We don't use item.setFields(itemAA) as doesn't cast streamFormat to proper value
            for each key in itemAA
                item[key] = itemAA[key]
            end for
            row.appendChild(item)
        end for
        RowItems.appendChild(row)
    end for
    return RowItems
End Function

text Laravel碳格式日期

carbon_year_month_day

https://stackoverflow.com/questions/36092553/how-to-format-a-carbon-date-to-get-the-full-month

Y = full Year
F = Month (label)
d = 2 digit day number

{{ \Carbon\Carbon::parse($new->uploaded_date)->format('Y F d')  }}
will print 2018 February 22

change the order of format('Y F d')  as needed

text 从#MassGIS #MAD #masteraddresslist geodatabase#ogr2ogr导出#address表

从#MassGIS #MAD #masteraddresslist geodatabase#ogr2ogr导出#address表

eatfmmmgo
ogr2ogr -f "CSV" -lco GEOMETRY=AS_XY madp.csv -t_srs EPSG:4326 MassGIS_Statewide_Address_Points.gdb -overwrite -progress -lco SRID=4326 MAD_ADDRESS_POINTS_GC

text guessTheNumber

guessTheNumber
# This is a guess the number game

import random

secret_number = random.randint(1, 20)
print('I am thionking of a number between 1 and 20.')

# Ask the player to guess 6 times.
for guesses_taken in range(1, 7):
    print('Take a guess.')
    guess = int(input())

    if guess < secret_number:
        print('Your guess is too low.')
    elif guess > secret_number:
            print('Your guess is too high.')
    else:
            break #This is condition is correct guess!

if guess == secret_number:
    print('Good job! You guessed my number in ' + str(guesses_taken) + ' guesses!')
    

text 每个模块只允许一次默认导出

每个模块只允许一次默认导出

Vuex installation problem
<template>
    <view>
      <h1>{{count}}</h1>
    </view>
</template>
 
<style>
.container {
  background-color: white;
  align-items: center;
  justify-content: center;
  flex: 1;
}
</style>

<script>
import Vue from "vue-native-core";
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 1
  },
  mutations: {
    increment(state) {
      // mutate state
      state.count++;
    }
  },
  actions: {
    increment(context) {
      context.commit("increment");
    }
  }
});
export default store;
</script>