Skip to content

Instantly share code, notes, and snippets.

View stevenbeales's full-sized avatar

Steven Beales stevenbeales

View GitHub Profile
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
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)
#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
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);
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;
#!/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
#
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){
#!/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]))
double_re = /\b(['A-Z]+) +\1\b/i