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
# Given a string with possibly unbalanced parentheses, return a string with balanced | |
# parentheses removing a minimal number of parentheses. | |
# Example: (abc)((), | |
# Output: (abc)() | |
def balance_parens(str) | |
stack = [] | |
str.each_char.with_index do |char, i| | |
case char | |
when '(' |
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
# dijkstra algorithm | |
Infinity = 1.0/0 | |
class Graph | |
attr_accessor :nodes | |
def initialize | |
@nodes = {} | |
end |
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 Heap | |
def initialize(type = :min) | |
@type = type | |
if @type == :min | |
@heap = [-1.0/0] | |
@compare = ->(a,b) { (a <=> b) < 0 } | |
elsif @type == :max | |
@heap = [1.0/0] | |
@compare = ->(a,b) { (b <=> a) > 0 } | |
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
def flatten(dict) | |
output_dict = {} | |
dict.each do |k,v| | |
if v.is_a? Hash | |
sub_dict = flatten(v) | |
sub_dict.each do |sk, sv| | |
output_dict[k+'.'+sk] = sv | |
end | |
else | |
output_dict[k] = v |
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
<?php | |
$site = "fullmooncalendar.net"; | |
$url = 'https://api.spyonweb.com/v1/domain/'.$site.'?access_token=YOUR_TOKEN_HERE'; | |
$response = file_get_contents($url); | |
$data = json_decode($response, true); | |
echo "<pre>\r\n"; | |
if ($data['status'] == "found") { | |
echo "Status: ".$data['status']."\r\n"; | |
// domain summary |
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
package main | |
import ( | |
"crypto/rand" | |
"encoding/binary" | |
"log" | |
"github.com/syndtr/goleveldb/leveldb" | |
) |