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
| const BLOOD_TYPES = { | |
| "O−": ["O−", "O+", "A−", "A+", "B−", "B+", "AB−", "AB+"], | |
| "O+": ["O+", "A+", "B+", "AB+"], | |
| "A−": ["A−", "A+", "AB−", "AB+"], | |
| "A+": ["A+", "AB+"], | |
| "B−": ["B−", "B+", "AB−", "AB+"], | |
| "B+": ["B+", "AB+"], | |
| "AB−": ["AB−", "AB+"], | |
| "AB+": ["AB+"] |
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 { useState, useMemo } from 'react'; | |
| // Usage | |
| function App() { | |
| const [count, setCount] = useState(0); | |
| const [wordIndex, setWordIndex] = useState(0); | |
| const words = ['hey', 'this', 'is', 'cool']; | |
| const word = words[wordIndex]; |
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
| mongodump -h <subdomain>.mlab.com:25372 -u <username> -p <password> --authenticationDatabase <dbname> -d <backup-folder-name> -o ~/Desktop/ | |
| && | |
| mongorestore --db <dbname> ~/Desktop/<backup-folder-name>/ |
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
| // By @coderitual | |
| // https://twitter.com/coderitual/status/1112297299307384833 | |
| // Remove any duplicates from an array of primitives. | |
| const unique = [...new Set(arr)] | |
| // Sleep in async functions. Use: await sleep(2000). | |
| const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms))); | |
| // Type this in your code to break chrome debugger in that line. |
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
| function mergeSort(array) { | |
| if(array.length < 2) return array; | |
| var middle = Math.floor(array.length / 2); | |
| var left = array.slice(0, middle); | |
| var right = array.slice(middle); | |
| return merge(mergeSort(left), mergeSort(right)); | |
| } |
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
| //Queue Data Structure | |
| function createQueue(){ | |
| const q = []; | |
| return { | |
| //enque | |
| enque(item){ | |
| return q.push(item); | |
| }, | |
| //deque |
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
| //Queue Data Structure | |
| function createQueue(){ | |
| const q = []; | |
| return { | |
| //enque | |
| enque(item){ | |
| return q.push(item); | |
| }, | |
| //deque |
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 eventManager = function(){ | |
| var subscriptions = {}; | |
| function subscribe(type, fn){ | |
| if(!subscriptions[type]) { | |
| subscriptions[type] = []; | |
| } | |
| if(subscriptions[type].indexOf(fn) == -1){ | |
| subscriptions[type].push(fn); |
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 insertionSort = (arr) => { | |
| arr = arr.slice(); | |
| for(var i = 1; i < arr.length; i++){ | |
| var current = arr[i]; | |
| var j = i - 1; | |
| while(j >= 0 && arr[j] > current){ | |
| arr[j + 1] = arr[j]; | |
| j--; | |
| } |
NewerOlder