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
def breadth_first_search(v) | |
raise ArgumentError, "No such vertex" if v < 0 or | |
vertices <= v | |
queue = LinkedQueue.new | |
is_visited = [] | |
queue.enter(Edge.new(-1,v)) | |
while !queue.empty? do | |
edge = queue.leave | |
next if is_visited[edge.w] | |
yield edge.v,edge.w |
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
def depth_first_search(v) | |
raise ArgumentError, "No such vertex" if v < 0 or | |
vertices <= v | |
is_visited = [] | |
visit = lambda do |v| | |
each_edge(v) do |v,w| | |
next if is_visited[w] | |
yield v,w | |
is_visited[w] = true | |
visit.call(w) |
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
#text_content = "string" | |
require "google/cloud/language" | |
language = Google::Cloud::Language.new | |
response = language.analyze_sentiment content: text_content, type: :PLAIN_TEXT | |
sentiment = response.document_sentiment |
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
function walkSync(currentDirPath, callback) { | |
// attrib: https://stackoverflow.com/questions/2727167/how-do-you-get-a-list-of-the-names-of-all-files-present-in-a-directory-in-node-j | |
fs.readdirSync(currentDirPath).forEach(function (name) { | |
var filePath = path.join(currentDirPath, name); | |
var stat = fs.statSync(filePath); | |
if (stat.isDirectory()) { | |
if (hasChildDirectories(filePath)) { | |
walkSync(filePath, callback); |
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
function hasChildDirectories(currentDirPath) { | |
let value = false; | |
fs.readdirSync(currentDirPath).forEach(function (name) { | |
var filePath = path.join(currentDirPath, name); | |
var stat = fs.statSync(filePath); | |
if (stat.isDirectory()) { | |
value = true; | |
} | |
}); | |
return value; |
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# Copyright 2012-2013 Zdenko Podobný | |
# Author: Zdenko Podobný | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# |
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
function searchDeep(obj,query,objName){ | |
var a = [] | |
var b = function(obj,query,c){ | |
if(~(a.indexOf(obj))) return [] | |
a.push(obj) | |
var d = [] | |
if(query in obj){ | |
d.push(c) | |
} | |
for(var j in obj){ |
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
#!/usr/bin/env python3 | |
from twx.botapi import TelegramBot, send_message | |
import time | |
from collections import Counter | |
polls = {} | |
def aggregate_votes(votes): | |
return '\n'.join('%s: %s' % (k,v) for k,v in sorted(Counter(votes.values()).items(), key=lambda x:x[1])) |
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
double_re = /\b(['A-Z]+) +\1\b/i |