Skip to content

Instantly share code, notes, and snippets.

Software Freestyle Engineer

Imam Ali Mustofa darkterminal

Software Freestyle Engineer
View GitHub Profile
darkterminal / harvesine.js
Created April 20, 2023 03:24
Calculate Distance from 2 Coordinates
View harvesine.js
function harvesine(pta, ptb) {
const [lat1, lon1] = pta.split(',')
const [lat2, lon2] = ptb.split(',')
// convert to radians
const rad1 = (lat1 * Math.PI) / 180;
const rad2 = (lat2 * Math.PI) / 180;
const dLat = ((lat2 - lat1) * Math.PI) / 180;
const dLon = ((lon2 - lon1) * Math.PI) / 180;
darkterminal / exportService.js
Created February 8, 2023 21:23 — forked from davidcsejtei/exportService.js
Export from JavaScript to Excel (xlsx)
View exportService.js
const xlsx = require('xlsx');
const path = require('path');
const exportExcel = (data, workSheetColumnNames, workSheetName, filePath) => {
const workBook = xlsx.utils.book_new();
const workSheetData = [
... data
const workSheet = xlsx.utils.aoa_to_sheet(workSheetData);
darkterminal / latency.txt
Created January 29, 2023 13:55 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers (~2012)
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
darkterminal /
Created January 10, 2023 11:57 — forked from quant61/
conversion to number in javascript

Some notes about conversion to number in javascript

javascript has lots of methods to convert any value to number

  • all methods could be divided into 2 groups: string and native methods
    • String methods are parseInt and parseFloat
    • Native mathods are Number and Math methods

all native methods behave the same way, sometimes with additional transform

darkterminal /
Created December 15, 2022 12:03 — forked from magnetikonline/
NSSM - the Non-Sucking Service Manager cheatsheet.
View console-colors.js
const createLogger = (backgroundColor, color) => {
const logger = (message, ...args) => {
if (logger.enabled === false) {
`background-color: ${backgroundColor}; color: ${color}; padding: 2px 4px;`,
darkterminal / gist:cbc0f6ff7b13d9ae17fe48f0ac9958bd
Created November 28, 2022 17:21 — forked from jacksonfdam/gist:3000275
Regular Expressions List
View gist:cbc0f6ff7b13d9ae17fe48f0ac9958bd
//Regular Expressions List
//Short Tutorial
\ // the escape character - used to find an instance of a metacharacter like a period, brackets, etc.
. // match any character except newline
x // match any instance of x
^x // match any character except x
[x] // match any instance of x in the bracketed range - [abxyz] will match any instance of a, b, x, y, or z
| // an OR operator - [x|y] will match an instance of x or y
darkterminal /
Created October 2, 2022 12:56 — forked from ionurboz/
Simple JavaScript debounce and throttle (Pure, Vanilla, Plain JS)

If you've written any kind of validation on user input, like onkeypress then you'll know that sometimes you want to throttle the amount of times your function runs. A good example of this is Ajax based username validation - you don't want to hit the server on every key press, because most users will be able to write their name in around 1/10th of a second, so you should throttle the ajax request until the input is dormant for 100ms.

So with a bit of magic JavaScript making use of the ever useful closure JavaScript offers, we can create a simple method to handle this for us:

function debounce(fn, delay) {
  var timer = null;
  return function () {
    var context = this, args = arguments;
 timer = setTimeout(function () {
darkterminal / strong-passwords.php
Created September 24, 2022 07:33 — forked from compermisos/strong-passwords.php
A user friendly, strong password generator PHP function.
View strong-passwords.php
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
View fix adb devices no permission
$ adb devices
List of devices attached
52003c2b58b445db no permissions (user in plugdev group; are your udev rules wrong?); see []
1> sudo usermod -aG plugdev $LOGNAME (
2> lsusb
3> sudo vi /etc/udev/rules.d/51-android.rules