Skip to content

Instantly share code, notes, and snippets.

View fotonmoton's full-sized avatar

Gregory fotonmoton

  • Ukraine
View GitHub Profile
@fotonmoton
fotonmoton / pbkdf2.c
Created April 2, 2019 22:15 — forked from bdd/pbkdf2.c
Generate a key from a passpharse w/ PBKDF2
/*
* Copyright (c) 2011 Berk D. Demir <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@fotonmoton
fotonmoton / JavaScriptCore_missing_array_iterator.js
Created December 8, 2018 15:34
JavaScriptCore Array.keys() object missing Symbol.iterator method :(
//Code:
const arr_iterator = Array(100).keys();
const is_iterator = arr_iterator[Symbol.iterator];
const arr = Array.from(arr_iterator);
console.log('typeof arr_iterator[Symbol.iterator]: ' + typeof is_iterator);
console.log('Array.isArray(arr): ' + Array.isArray(arr));
console.log('arr: ' + JSON.stringify(arr));
/*
Logs from android emulator:
@fotonmoton
fotonmoton / error-handling-with-fetch.md
Created December 1, 2017 14:17 — forked from odewahn/error-handling-with-fetch.md
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })
@fotonmoton
fotonmoton / priority_linux.c
Created February 19, 2016 17:49
priority CPU scheduling algorithm (Linux)
// Compile with: gcc priority_linux.c -lncurses -o lol
// if you doesn't have ncurses lib type in terminal: sudo apt-get install libncurses5-dev
// http://www.ssau.ru/files/education/metod_1/%D0%9A%D1%83%D0%BF%D1%80%D0%B8%D1%8F%D0%BD%D0%BE%D0%B2%20%D0%90.%D0%92.%20%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D1%8B%20%D0%BF%D0%BB%D0%B0%D0%BD%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F.pdf
#include<stdio.h>
#include<stdlib.h>
#include<ncurses.h>
int main()
{
@fotonmoton
fotonmoton / priority_win.c
Last active February 19, 2016 17:46
priority CPU scheduling algorithm (Win)
// Run VS dev terminal: start button -> serch "dev" -> start VS developer terminal
// Compile with: cl priority_win.c
// http://www.ssau.ru/files/education/metod_1/%D0%9A%D1%83%D0%BF%D1%80%D0%B8%D1%8F%D0%BD%D0%BE%D0%B2%20%D0%90.%D0%92.%20%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D1%8B%20%D0%BF%D0%BB%D0%B0%D0%BD%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F.pdf
#include<stdio.h>
int main()
{
int p[20],bt[20],pri[20], wt[20],tat[20],i, k, n, temp;
float wtavg, tatavg;
@fotonmoton
fotonmoton / rr_linux.c
Last active February 19, 2016 17:44
round robin scheduling algorithm (Linux)
// Run VS dev terminal: start button -> serch "dev" -> start VS developer terminal
// Compile with: cl rr_win.c
// http://www.ssau.ru/files/education/metod_1/%D0%9A%D1%83%D0%BF%D1%80%D0%B8%D1%8F%D0%BD%D0%BE%D0%B2%20%D0%90.%D0%92.%20%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D1%8B%20%D0%BF%D0%BB%D0%B0%D0%BD%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F.pdf
#include<stdio.h>
#include<stdlib.h>
#include<ncurses.h>
int main()
@fotonmoton
fotonmoton / rr_win.c
Last active February 19, 2016 17:45
round robin scheduling algorithm (Win)
// Run VS dev terminal: start button -> serch "dev" -> start VS developer terminal
// Compile with: cl rr_win.c
// http://www.ssau.ru/files/education/metod_1/%D0%9A%D1%83%D0%BF%D1%80%D0%B8%D1%8F%D0%BD%D0%BE%D0%B2%20%D0%90.%D0%92.%20%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D1%8B%20%D0%BF%D0%BB%D0%B0%D0%BD%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F.pdf
#include<stdio.h>
#include<windows.h>
int main()
{
@fotonmoton
fotonmoton / sjf_linux.c
Last active September 7, 2022 23:12
shortest job first scheduling algorithm (Linux)
// Compile with: gcc sjf_linux.c -lncurses -o lol
// if you doesn't have ncurses lib type in terminal: sudo apt-get install libncurses5-dev
// http://www.ssau.ru/files/education/metod_1/%D0%9A%D1%83%D0%BF%D1%80%D0%B8%D1%8F%D0%BD%D0%BE%D0%B2%20%D0%90.%D0%92.%20%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D1%8B%20%D0%BF%D0%BB%D0%B0%D0%BD%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F.pdf
#include<stdio.h>
#include<stdlib.h>
#include<ncurses.h>
int main()
@fotonmoton
fotonmoton / sjf_win.c
Last active February 19, 2016 17:45
shortest job first scheduling algorithm (Win)
// Run VS dev terminal: start button -> serch "dev" -> start VS developer terminal
// Compile with: cl sjf_win.c
// http://www.ssau.ru/files/education/metod_1/%D0%9A%D1%83%D0%BF%D1%80%D0%B8%D1%8F%D0%BD%D0%BE%D0%B2%20%D0%90.%D0%92.%20%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D1%8B%20%D0%BF%D0%BB%D0%B0%D0%BD%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F.pdf
#include<stdio.h>
#include<conio.h>
#include<windows.h>
int main()
{
@fotonmoton
fotonmoton / fcfs_win.c
Last active February 19, 2016 17:32
first come first serve algorithm (Win)
// Run VS dev terminal: start button -> serch "dev" -> start VS developer terminal
// Compile with: cl fcfs_win.c
// http://www.ssau.ru/files/education/metod_1/%D0%9A%D1%83%D0%BF%D1%80%D0%B8%D1%8F%D0%BD%D0%BE%D0%B2%20%D0%90.%D0%92.%20%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D1%8B%20%D0%BF%D0%BB%D0%B0%D0%BD%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F.pdf
#include<stdio.h>
#include<conio.h>
#include<windows.h>
int main()
{