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
| # Create a directory | |
| mkdir ~/tmux-install | |
| cd ~/tmux-install | |
| # Get the files | |
| curl -OL https://www.openssl.org/source/openssl-1.0.2l.tar.gz | |
| curl -OL https://github.com/tmux/tmux/releases/download/2.3/tmux-2.3.tar.gz | |
| curl -OL https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz | |
| # Extract them |
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 poll = ({ fn, validate, interval, maxAttempts }) => { | |
| console.log('Start poll...'); | |
| let attempts = 0; | |
| const executePoll = async (resolve, reject) => { | |
| console.log('- poll'); | |
| const result = await fn(); | |
| attempts++; | |
| if (validate(result)) { |
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
| let visited = new WeakSet(); | |
| let onur = { name: "Onur" }; | |
| let ozge = { name: "Özge" }; | |
| let avni = { name: "Avni" }; | |
| visited.add(onur); // Onur`u ziyaret edenlere ekleyelim | |
| visited.add(ozge); // sonra Özge`yi | |
| visited.add(onur); // Onur`u tekrar eklemeye çalışalım |
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 ClearableWeakMap { | |
| constructor(init) { | |
| this._wm = new WeakMap(init); | |
| } | |
| clear() { | |
| this._wm = new WeakMap(); | |
| } | |
| delete(k) { | |
| return this._wm.delete(k); | |
| } |
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
| let cache = new WeakMap(); | |
| // sonuçları hesaplar ve tekrar hatırlar | |
| export default function process(obj) { | |
| // eğer WeakMap'imiz objemizi içermiyorsa | |
| if (!cache.has(obj)) { | |
| let result = cb(); | |
| // Önbelleğe almak için WeakMap'imizin içine ekleyelim | |
| cache.set(obj, result); |
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
| let onur = { name: "Onur" }; | |
| let weakMap = new WeakMap(); | |
| weakMap.set(onur, "..."); | |
| // refenransının üzerine yazalım | |
| onur = null; | |
| // onur'u hafızadan silmiş olduk |
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
| let weakMap = new WeakMap(); | |
| let obj = {}; | |
| weakMap.set(obj, "deger"); | |
| // obj anahar olarak weakMap içerisine eklenir. | |
| // string bir anahtar kullanamazsınız | |
| weakMap.set("test", "tesst"); | |
| // Error, hata alacağız çünkü "test" bir obje değil |
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
| let obj = { | |
| name: "John", | |
| age: 30 | |
| }; | |
| // new Map([iterable]) | |
| let map = new Map(Object.entries(obj)); | |
| console.log(map.get('name')); | |
| // John |
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
| let onur = { name: 'Onur' }; | |
| let ozge = { name: 'Özge' }; | |
| let avni = { name: 'Avni' }; | |
| let set = new Set(); | |
| set.add(onur); | |
| set.add(ozge); | |
| set.add(avni); | |
| set.add(onur); // ikinci birden fazla aynı değeri ekleyemeyiz!. |
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 myHeavyFunc(x) { | |
| // Bazı yogun, ve yavaş çalışacak bazı işlemleri bu alanda yazdığınızı farzediyoruz. | |
| // Yada aynı değerlerle tekrarlayacağınız ve matematiksel işlemler yaptığımızı düşünebiliriz | |
| console.log(`x: ${x}`); | |
| return x; | |
| } | |
| function caching(func) { | |
| let cache = new Map(); |
NewerOlder