This file contains hidden or 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
# Manually secure port 6379 | |
sudo iptables -A INPUT -p tcp --dport 6379 -s xxx.xxx.xxx.xxx -j ACCEPT | |
sudo iptables -A INPUT -p tcp --dport 6379 -j DROP | |
sudo iptables -L | |
# Save current firewall config | |
sudo iptables-save > /etc/iptables.conf | |
# Load iptables.conf on startup | |
sudo nano /etc/rc.local |
This file contains hidden or 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 'benchmark' | |
examples = [] | |
res1 = [] | |
res2 = [] | |
def f1(arr, k) | |
arr.sort[arr.size - k] | |
end |
This file contains hidden or 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 an array of integers, A of length N, find out the maximum sum sub-array of non negative numbers from A. | |
/** | |
* @input A : Integer array | |
* | |
* @Output Integer array. | |
*/ | |
package main | |
import "fmt" |
This file contains hidden or 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 MySolution | |
# @param a : string | |
# @param b : string | |
# @returns an integer | |
def compare_versions(a, b) | |
aa = a.split('.') | |
bb = b.split('.') | |
i = 0 |
This file contains hidden or 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
# @param {Integer} n | |
# @return {String} | |
def convert_to_title(n) | |
res = '' | |
begin | |
rem = n % 26 | |
n /= 26 | |
rem = if rem.zero? |
This file contains hidden or 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
# @param {Integer} n | |
# @return {Integer} | |
def binary_gap(n) | |
res = 0 | |
while n.nonzero? do | |
n &= n << 1 | |
res += 1 | |
end |
This file contains hidden or 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
# @param {String} address | |
# @return {String} | |
def defang_i_paddr(address) | |
address.split('.').join('[.]') | |
end |
This file contains hidden or 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
# Definition for a binary tree node. | |
# class TreeNode | |
# attr_accessor :val, :left, :right | |
# def initialize(val = 0, left = nil, right = nil) | |
# @val = val | |
# @left = left | |
# @right = right | |
# end | |
# end | |
# @param {TreeNode} root |
This file contains hidden or 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
# @param {String} s | |
# @return {Integer} | |
def min_add_to_make_valid(s) | |
res = 0 | |
balance = 0 | |
s.each_char do |c| | |
balance += c == '(' ? 1 : -1 | |
if balance < 0 |
This file contains hidden or 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
# @param {Integer} x | |
# @return {Boolean} | |
def is_palindrome(x) | |
return false if x.negative? | |
s = x.abs.to_s | |
i = 0 | |
j = s.length - 1 |
OlderNewer