View nationalCodeGenerator.js
This file contains 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 generateNationalCode() { | |
let numbers = [] | |
let sum = 0 | |
for (let i = 10; i >= 2; i--) { | |
let j = Math.floor(Math.random() * 10) | |
numbers.push(j) | |
sum += j * i | |
} | |
const m = sum % 11 | |
numbers.push(m < 2 ? m : 11 - m) |
View amd_gpu_overclock.bash
This file contains 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
#!/bin/bash | |
set_voltage() { | |
echo "before for card #${1}:" | |
cat /sys/class/drm/card$1/device/pp_od_clk_voltage | |
echo "" | |
echo "m 2 1985 900" > /sys/class/drm/card$1/device/pp_od_clk_voltage | |
echo "s 7 1100 900" > /sys/class/drm/card$1/device/pp_od_clk_voltage | |
echo "c" > /sys/class/drm/card$1/device/pp_od_clk_voltage |
View implement MinHeap - priority list
This file contains 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 MinHeap { | |
constructor() { | |
this.data = []; | |
} | |
add (item) { | |
let newData = [...this.data, item]; | |
// it's the first item in the heap | |
if (this.data.length === 0) { | |
return this.data = newData; |
View Queue example - traverse graph
This file contains 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
// graph image https://imagebin.ca/v/4fEWnt6XNraD | |
// 11. Breadth first search and queue [udemy easy to advanced data structure] | |
class Node { | |
constructor (value = null) { | |
this.value = value; | |
this.neighbours = [] | |
} | |
setNeighbours (neighbours) { |
View stack example - bracket match
This file contains 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 input = '[{}]' | |
let input2 = '[[{}]()]' | |
let input3 = '[{})[]' | |
function isOk (inputString) { | |
let arr = inputString.split(''); | |
let stack = [] | |
for (let i = 0; i < arr.length; i++) { |
View gist:ea5ff438ead0bbf0a87dfe7ebb8896b0
This file contains 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
// Check Iranian National Code Validity - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go | |
// بررسی صحت کد ملی ایران - کلوژر، سیشارپ، روبی، جاوااسکریپت، پایتون، اسکالا، جاوا ۸، پیاچپی، سی، گو | |
// در نسخههای قبل یکسان بودن اعداد نا معتبر تشخیص داده میشد ولی | |
// اعداد یکسان نامعتبر نیست http://www.fardanews.com/fa/news/127747 | |
/** | |
* @author Ebrahim Byagowi (2013-) | |
* @lincense: Public Domain | |
*/ |