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
| // Define the pins for your 5 LEDs | |
| int ledPins[] = {2, 3, 4, 5, 6}; | |
| void setup() { | |
| // Initialize all 5 pins as OUTPUT | |
| for (int i = 0; i < 5; i++) { | |
| pinMode(ledPins[i], OUTPUT); | |
| } | |
| } |
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 subprocess | |
| import json | |
| # Your command string | |
| command = """ | |
| df --output=source,size,used,avail,pcent,target -B G | \ | |
| grep '^/dev/' | \ | |
| awk '{print $1, $2, $3, $4, $5, $6}' | \ | |
| jq -R -s '[split("\\n") | .[] | select(length > 0) | split(" ") | {Filesystem: .[0], Size_GB: .[1], Used_GB: .[2], Avail_GB: .[3], Use_Percent: .[4], Mounted_on: .[5]}]' | |
| """ |
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
| All files with a .yml extension. | |
| Tabs are NOT allowed, use spaces ONLY. | |
| You MUST indent your properties and lists with 1 or more spaces. | |
| All keys/properties are case-sensitive. ("ThIs", is not the same as "thiS") | |
| For Ansible, nearly every YAML file starts with a list. | |
| Each item in the list is a list of key/value pairs, commonly called a “hash” or a “dictionary”. | |
| So, we need to know how to write lists and dictionaries in YAML. | |
| All YAML files (regardless of their association with Ansible or not) can optionally begin with --- and end with .... |
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
| from collections import defaultdict | |
| class Graph: | |
| def __init__(self): | |
| self.graph = defaultdict(dict) | |
| def addEdge(self,x,y,w): | |
| if x in self.graph.keys(): | |
| #self.graph[x].update({y:w}) | |
| self.graph[x][y] = w |
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 bellman_ford(graph,source,dest): | |
| pred,dist = initialize_graph(graph,src) | |
| for i in range(len(graph)-1): | |
| for k in graph: | |
| for v in graph[k]: | |
| relax(graph,k,v,dist,pred) | |
| def relax(graph,source,Neighbour,dist,pred): | |
| if dist[source] + graph[source][Neighbour] < dist[Neighbour]: |
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 flatout_list(somelist): | |
| ... flat_list = [] | |
| ... def check_list(alist): | |
| ... for elem in alist: | |
| ... if isinstance(elem,list): | |
| ... #if type(elem) is list: Alternative way | |
| ... check_list(elem) | |
| ... else: | |
| ... flat_list.append(elem) | |
| ... check_list(somelist) |
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
| ''' | |
| Provides performance boost when Construction and destruction of object can become very expensive operation if it occurs very often. | |
| Object pool is a managed set of reusable objects. | |
| Clients then “check out” objects from the pool return them back when they don’t need them any more. But it’s not that easy as it sounds. | |
| The manager of the pool has to deal with various problems. | |
| ''' | |
| # Source - http://radek.io/2011/08/04/design-pattern-object-pool/ |
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
| ''' | |
| Provide the ability to add managed attributes to objects. | |
| The methods needed to create a descriptor are __get__, __set__ and __delete__. | |
| If you define any of these methods, then you have created a descriptor. | |
| Idea is to get, set or delete attributes from your object’s dictionary. | |
| When you access a class attribute, this starts the lookup chain | |
| __get__(self, obj, type=None), returns value | |
| __set__(self, obj, value), returns None | |
| __delete__(self, obj), returns None |
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 Same_State(object): | |
| __shared_state = {} | |
| def __init__(self): | |
| self.__dict__ = self.__shared_state | |
| self.state = 'Init' | |
| def __str__(self): | |
| return self.state |
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
| from collections import defaultdict | |
| class Graph: | |
| def __init__(self): | |
| self.graph = defaultdict(list) | |
| def addEdge(self,u,v): | |
| self.graph[u].append(v) | |
| def bfs(self,vertex): |
NewerOlder