Skip to content

Instantly share code, notes, and snippets.

@30percent
30percent / gist:03dddbd176bb88210cba85b76e8518ae
Created July 31, 2018 21:24
Find ternaries (with occasional others caught in)
([-\r\n\w\s\[\](){}=!\/%*+&^|."']*)\?([-\r\n\w\s\[\](){}=!\/%*+&^|."']*)([\w]+)([-\r\n\w\s\[\](){}=!\/%*+&^|."']*):([-\r\n\w\s\[\](){}=!\/%*+&^|."']*)
@30percent
30percent / SortingAlgorithms.js
Created June 30, 2015 03:30
A script that allows for choosing algorithm based on requirements. Functionally based. In progress.
function Algorithm(name, listOSortables){
this.name = name;
this.sortables = listOSortables;
this.unsortables = {};
this.addSortable = function(name, sortable) {
this.sortables[name] = sortable;
return this;
};
this.addUnsortable = function(name, contents) {
this.unsortables[name] = contents;
@30percent
30percent / linkedlistext.py
Last active August 29, 2015 14:22
Linked List extended functions
'''
params: myNode - Node object; Must not be member of Circular LL
alters: Any List container 'pointing' indirectly to myNode
* Removes all objects enroute to end of List that hold same contents values
returns: None
'''
def removeDuplicates(myNode):
tempNode = myNode
while tempNode.getNext() != None:
toRemove = tempNode.getNext()
@30percent
30percent / linkedlist.py
Last active August 29, 2015 14:22
Basic Singly-Linked List in Python
class Node:
def __init__(self, data):
self.contents = data
self.next = None
def getContents(self):
return self.contents
def getNext(self):
return self.next
def revWordList(input):
return ' '.join(reversed(input.split(' ')))
print(revWordList("world! Hello,"))
@30percent
30percent / stringrev.py
Created May 28, 2015 20:05
Simply reverse a string
def revStrLoop(input):
outList = [0]*len(input)
for i, char in enumerate(input):
outList[len(input)-i-1] = char
return ''.join(outList)
def revStrList(input):
return ''.join(reversed(list(input)))
def revStrSlice(input):
@30percent
30percent / permutation.py
Created May 28, 2015 20:01
Given two strings, determine if they are permutations of each other
from collections import defaultdict
def charCount(inStr):
charDict = defaultdict(int)
for char in inStr:
charDict[char] += 1
return charDict
def isPermutation(leftStr, rightStr):
return charCount(leftStr) == charCount(rightStr)