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
| #! /usr/bin/env python | |
| """Git pre-commit hook to run pylint on python files. | |
| To install: | |
| wget https://gist.github.com/nivbend/7e0e306a98138916b3c9#file-run_pylint-py -O .git/hooks/pre-commit | |
| """ | |
| from __future__ import print_function | |
| from subprocess import check_output, CalledProcessError | |
| from sys import stderr |
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
| """Module to consume events generated from RabbitMQ.""" | |
| from rabbitmq.connection_handler import ConnectionHandler | |
| from event_consumer_utils import * | |
| connection = ConnectionHandler.get_connection() | |
| channel = connection.channel() | |
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
| // Usage: | |
| // p(instance)('privateMethod)(arg1, arg2, arg3) | |
| class PrivateMethodCaller(x: AnyRef, methodName: String) { | |
| def apply(_args: Any*): Any = { | |
| val args = _args.map(_.asInstanceOf[AnyRef]) | |
| def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass) | |
| val parents = _parents.takeWhile(_ != null).toList | |
| val methods = parents.flatMap(_.getDeclaredMethods) | |
| val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found")) |
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
| import random | |
| a=str(random.randint(1000,9999)) | |
| while a!=b: | |
| b=input('Guess the 4 digit number : ') | |
| cow=0 | |
| bull=0 | |
| for i in a: | |
| if i in b and a.index(i)==b.index(i): | |
| cow+=1 | |
| elif i in b and a.index(i)!=b.index(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
| a=input("Enter a long string ").split(" ") | |
| a=a[::-1] | |
| a=" ".join(a) | |
| print(a) |
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
| # Without using sets | |
| for i in list1: | |
| if i not in list2: | |
| list2=list2+[i] | |
| # Using sets | |
| print(set(list1)) |
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
| def fibonacci(): | |
| a=1 | |
| b=0 | |
| c=0 | |
| n=int(input()) | |
| for i in range(0,n): | |
| c=a+b | |
| a=b | |
| b=c | |
| print(c) |
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
| def prime(): | |
| a=int(input("Enter a number ")) | |
| for i in range(2,a): | |
| if a%i==0: | |
| break | |
| else: | |
| continue | |
| if i==(a-1): | |
| print("prime") | |
| else: |
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
| def guess(): | |
| a=random.randint(1,9) | |
| b=int(input("Guess the number ")) | |
| if b==a: | |
| print("You guessed it right!") | |
| return 1 | |
| else: | |
| if b<a: | |
| print("Your guess is low") | |
| return 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
| def game(): | |
| p1=input("Player 1 input rock,paper or scissors ") | |
| p2=input("Player 2 input rock,paper or scissors ") | |
| if p1==p2: | |
| print("It is a tie!") | |
| else: | |
| if p1=="rock": | |
| if p2=="paper": | |
| print("Player 2 wins!") | |
| elif p2=="scissors": |
NewerOlder