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
## | |
## Block referer spam on Nginx | |
#check if '/etc/nginx/conf.d/*.conf' is included in nginx.conf | |
root@fooserver:/etc/nginx# cat nginx.conf | grep include | |
include /etc/nginx/mime.types; | |
include /etc/nginx/conf.d/*.conf; | |
include /etc/nginx/sites-enabled/*; | |
#create a blacklist |
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
package main | |
import "fmt" | |
type Awesomizer interface { | |
Awesomize() string | |
} | |
type Foo struct{} |
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
package main | |
import "fmt" | |
import "runtime" | |
func main() { | |
fmt.Println("OS Detected: ", runtime.GOOS) | |
switch os := runtime.GOOS; os { | |
case "darwin": | |
fmt.Println("Mac OS Hipster") |
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
#Calculate sum of the elements in a list 'recirsively' | |
def listsum(numList): | |
if len(numList) == 1: | |
return numList[0] | |
else: | |
return numList[0] + listsum(numList[1:]) | |
print(listsum([1,3,5,7,9])) |
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 Node(object): | |
def __init__(self, name): | |
self.name = name | |
self.deps = [] | |
def make_dep(self, node): | |
if node not in self.deps: | |
self.deps.append(node) | |
def install(self): | |
# install all depedencies & pkg | |
resolved = [] |
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 two input binary strings, calculate their sum | |
s1 = '1' | |
s2 = '1101' | |
s1l = list(s1)[::-1] | |
s2l = list(s2)[::-1] | |
# Padding | |
if len(s1l) < len(s2l): | |
s1l = s1l + ['0'] * (len(s2l) - len(s1l)) | |
elif len(s2l) < len(s1l): |
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 a dictionary and a string, check if the string forms a proper sentence | |
''' | |
thisisasentence -> True | |
thisisnotasantance -> False | |
''' | |
dictionary = set([ | |
'this', | |
'is', | |
'a', | |
'i', |
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
# Check if a string is palindrome or not | |
# Ignore all non-letter characters in the string and check should be case-insensitive | |
#"a" | |
#"ABba" | |
#"..a..a" | |
#"A man, a plan, a canal, Panama!" | |
#"amanaplanacanalpanama" | |
#"amanap".. |
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
#Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the | |
#multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz" | |
for i in xrange(1, 101): | |
if i % 15 == 0: #L.C.M of 3 & 5 | |
print "FizzBuzz" | |
elif i % 3 == 0: | |
print "Fizz" | |
elif i % 5 == 0: | |
print "Buzz" |
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
#recursion technique is always fascinating! | |
def factorial(n): | |
return 1 if (n < 1) else n * factorial(n-1) | |
factorial(5) |