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 System; | |
| using System.Threading; | |
| public class Debouncer : IDisposable | |
| { | |
| private Thread thread; | |
| private volatile Action action; | |
| private volatile int delay = 0; | |
| private volatile int frequency; |
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
| void TimeAgo(DateTime date) | |
| { | |
| // 1000 millisecs = 1 sec | |
| // 60 secs = 1 min | |
| // 60 mins = 1 hr | |
| // 24 hrs = 1 day | |
| var diff = DateTime.Now - date; | |
| var millis = diff.TotalMilliseconds; | |
| var millisInDay = 86400 * 1000; | |
| var daysInMillis = millis / millisInDay; |
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 hole = new RoundHole(5); | |
| var rPeg = new RoundPeg(5); | |
| hole.Fits(rPeg).Dump(); // True | |
| var sm_sqpeg = new SquarePeg(5); | |
| var lg_sqpeg = new SquarePeg(10); | |
| //hole.Fits(sm_sqpeg); // Error: won't compile (incompatible types) | |
| var sm_sqpeg_adapter = new SquarePegAdapter(sm_sqpeg); | |
| var lg_sqpeg_adapter = new SquarePegAdapter(lg_sqpeg); |
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 download(fileUrl, filename) { | |
| const a = document.createElement("a") | |
| a.href = fileUrl | |
| a.setAttribute("download", filename) | |
| a.click() | |
| } | |
| // With Axios | |
| import axios from "axios" |
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
| # brew install dos2unix | |
| find . -name '*.*' -print0 |xargs -0 dos2unix |
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
| // Redux basics | |
| // Redux is made up of 3 key parts, namely: | |
| // Store | |
| // Reducer | |
| // Action/ActionCreator | |
| const store = { | |
| cartReducer: {}, | |
| profileReducer: {}, | |
| }; |
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
| // The following fixes the inconsisties in the JS % (modulus) operator when used on fractional numbers | |
| // Example 1 | |
| // Multiply both sides of operand by 10000 | |
| let remainder = (100 * 10000) % (0.33 * 10000); | |
| // Example 2 | |
| // Divide the numbers, then apply the modulus of result by 1 | |
| remainder = (100 / 0.33) % 1; |
I hereby claim:
- I am codejockie on github.
- I am codejockie (https://keybase.io/codejockie) on keybase.
- I have a public key ASCRr5z1RHJ2EqiU25TuXRQHvlNVEbzC4tITsZGRLmd-LQo
To claim this, I am signing this object:
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
| Lesson 1 - Iterations | |
| - BinaryGap - https://codility.com/demo/results/trainingU2FQPQ-7Y4/ | |
| Lesson 2 - Arrays | |
| - OddOccurrencesInArray - https://codility.com/demo/results/trainingFN5RVT-XQ4/ | |
| - CyclicRotation - https://codility.com/demo/results/trainingSH2W5R-RP5/ | |
| Lesson 3 - Time Complexity | |
| - FrogJmp - https://codility.com/demo/results/training6KKWUD-BXJ/ | |
| - PermMissingElem - https://codility.com/demo/results/training58W4YJ-VHA/ |