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
| # prereqs: | |
| # Create a Twitter app and generate oauth credentials at https://apps.twitter.com | |
| # python 2.7 | |
| # pip install oauth2 | |
| import oauth2 as oauth | |
| import json | |
| import urllib | |
| CONSUMER_KEY = 'your consumer key' |
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
| # Git branch in prompt. | |
| parse_git_branch() { | |
| git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
| } | |
| # PS1 prompt | |
| export PS1="\w\[\033[32m\]\$(parse_git_branch)\[\033[00m\]$ " |
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 maxSubarray(numbers): | |
| currentMax = 0 | |
| totalMax = 0 | |
| for n in numbers: | |
| currentMax = max(0, currentMax + n) | |
| totalMax = max(totalMax, currentMax) | |
| return totalMax | |
| numbers = [-10, 2,2,-4,2,3,4,-5] | |
| print(str(maxSubarray(numbers))) # 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
| nmap -PN localhost | |
| ----------------------- | |
| PORT STATE SERVICE | |
| 631/tcp open ipp | |
| 1023/tcp open netvenuechat |
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
| var fs = require('fs'); | |
| var parse = require('csv-parse'); | |
| var consumed = 0; | |
| var burned = 0; | |
| var numDays = 0; | |
| var parser = parse({delimiter: ';'}, function(err, data){ | |
| data.forEach(function(data){ | |
| ++numDays; |
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
| // using StringBuffer | |
| boolean isPalindrome(String s) { | |
| StringBuffer stringBuffer = new StringBuffer(s); | |
| StringBuffer reverse = new StringBuffer(s); | |
| reverse.reverse(); | |
| return stringBuffer.toString().equals(reverse.toString()); | |
| } | |
| // in place | |
| boolean isPalindrome(String input) { |
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
| // palindrome will have even letter counts and at most one odd letter count | |
| boolean isPalindromPermutation(String input) { | |
| Map<String, Integer> frequency = new HashMap<String, Integer>(); | |
| for(String s : input.split("")) { | |
| if(!frequency.containsKey(s)) { | |
| frequency.put(s, 1); | |
| } else { | |
| frequency.put(s, 1 + frequency.get(s)); | |
| } | |
| } |
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
| // pale, ple -> true | |
| // pales, pale -> true | |
| // pale, bale -> true | |
| // pale, bake -> false | |
| boolean isOneAway(String a, String b) { | |
| int aLength = a.length(); | |
| int bLength = b.length(); | |
| int shortIndex = 0; | |
| int longIndex = 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
| // aabccccaaa -> aabccccaaa | |
| String compressString(String input) { | |
| StringBuilder compressed = new StringBuilder(); | |
| int count = 1; | |
| String[] arr = input.split(""); | |
| for(int i = 0; i < arr.length; i++) { | |
| ++count; | |
| if(i + 1 >= arr.length || !arr[i + 1].equals(arr[i])) { | |
| compressed.append(arr[i]); | |
| compressed.append(Integer.toString(count)); |
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
| boolean isPalindrome(Node n){ | |
| Node fast = n; | |
| Node slow = n; | |
| // push first half onto stack, then compare with second half | |
| Stack<Integer> s = new Stack<Integer>(); | |
| while(fast != null && fast.next != null) { | |
| s.push(slow.data); | |
| slow = slow.next; | |
| fast = fast.next.next; |