Skip to content

Instantly share code, notes, and snippets.

View svalleru's full-sized avatar

Shan Valleru svalleru

View GitHub Profile
##
## 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
@svalleru
svalleru / GoInterface.go
Last active October 16, 2015 19:38
Simplae Interface & Struct in Go
package main
import "fmt"
type Awesomizer interface {
Awesomize() string
}
type Foo struct{}
@svalleru
svalleru / GoOS.go
Last active March 7, 2021 04:45
Detect OS in Go
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")
@svalleru
svalleru / RecursiveSum.py
Last active October 16, 2015 19:39
RecursiveSum
#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]))
@svalleru
svalleru / Installer.py
Last active October 16, 2015 19:39
PackageInstaller | DependencyWalker
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 = []
@svalleru
svalleru / BinarySum
Created May 18, 2015 21:36
BinarySum
# 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):
@svalleru
svalleru / SentenceCheck.py
Last active October 16, 2015 19:39
SentenceCheck
#Given a dictionary and a string, check if the string forms a proper sentence
'''
thisisasentence -> True
thisisnotasantance -> False
'''
dictionary = set([
'this',
'is',
'a',
'i',
@svalleru
svalleru / PalindromeCheck.py
Last active October 16, 2015 19:39
PalindromeCheck
# 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"..
#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"
@svalleru
svalleru / RecursiveFactorial.py
Last active October 16, 2015 19:40
RecursiveFactorial
#recursion technique is always fascinating!
def factorial(n):
return 1 if (n < 1) else n * factorial(n-1)
factorial(5)