Skip to content

Instantly share code, notes, and snippets.

View Ormadont's full-sized avatar

Evgeniy Pavlovich Demyanov Ormadont

  • Krost
  • Moscow, Russia
View GitHub Profile
@Ormadont
Ormadont / simpleGuid.js
Created March 28, 2022 11:49
simple guid
const newGuid = Date.now().toString(36) + Math.random().toString(36).substring(2);
export default newGuid;
@Ormadont
Ormadont / objectToPrimitive.js
Last active August 27, 2021 08:53
JS: transform object to primitive
function transform(hint) {
return hint == 'string' ? this.name : this.height
}
let man = {
name: 'Evgeniy',
height: 185,
[Symbol.toPrimitive]: transform
}
@Ormadont
Ormadont / GitConfigHttpProxy.md
Created July 30, 2021 10:02 — forked from evantoli/GitConfigHttpProxy.md
Configure Git to use a proxy

Configure Git to use a proxy

In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

Use Proxy for Git/GitHub

Generally, the Git proxy configuration depends on the Git Server Protocal you use. And there're two common protocals: SSH and HTTP/HTTPS. Both require a proxy setup already. In the following, I assume a SOCKS5 proxy set up on localhost:1080. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later.

SSH Protocol

When you do git clone ssh://[user@]server/project.git or git clone [user@]server:project.git, you're using the SSH protocal. You need to configurate your SSH client to use a proxy. Add the following to your SSH config file, say ~/.ssh/config:

ProxyCommand nc -x localhost:1080 %h %p
@Ormadont
Ormadont / FirstSysEvent.cs
Created March 23, 2019 16:26
Время первого события текущего дня из журнала событий Windows
sysLog = new EventLog();
sysLog.Log = "System";
IEnumerable<EventLogEntry> Entries = sysLog.Entries.Cast<EventLogEntry>();
// время первого события текущего дня
var startTime =
(from l in Entries
where l.TimeGenerated.DayOfYear == nowTime.DayOfYear // только события сегодняшнего дня
select l.TimeGenerated)
.Min();
@Ormadont
Ormadont / async-GET-Requests.js
Created June 14, 2018 17:34
boilerplate code: async GET Requests
//boilerplate code: async GET Requests
//The async keyword will ensure that the function returns a promise.
const getData = async () => {
try {
const response = await fetch('https://api-to-call.com/endpoint');
if (response.ok) {
//Since .json() is an asynchronous method we have to await until the promise status is resolved. Then we store the value to know what data the JSON holds.
const jsonResponse = await response.json();
return jsonResponse;
@Ormadont
Ormadont / postRequest-fetch.js
Created June 13, 2018 18:43
// boilerplate code necessary to create a POST request using the fetch()
//The boilerplate code for an AJAX POST request using fetch.
fetch('https://api-to-call.com/endpoint', {
method: 'POST',
body: JSON.stringify({id: '200'})
}).then( response => {
if (response.ok) {
return response.json();
}
throw new Error('Request failed!');
@Ormadont
Ormadont / getRequest-fetch.js
Created June 13, 2018 17:00
Boilerplate code necessary to create a GET request using the fetch()
// boilerplate code necessary to create a GET request using the fetch()
fetch('https://api-to-call.com/endpoint').then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Request failed!');
}, networkError => {
console.log(networkError.message);
}).then( jsonResponse => {
@Ormadont
Ormadont / postRequest.js
Created June 11, 2018 16:37
The boilerplate code for an AJAX POST request using an XMLHttpRequest object.
//The boilerplate code for an AJAX POST request using an XMLHttpRequest object.
//The XMLHttpRequest object is used in JavaScript to interact with servers.
const xhr = new XMLHttpRequest();
//The URL will direct the request to the correct server.
const url = 'https://api-to-call.com/endpoint';
//JSON.stringify() will convert a value to a JSON string.
//By converting the value to a string, we can then send the data to a server.
const data = JSON.stringify({id: '200'});
@Ormadont
Ormadont / html clean
Created June 7, 2018 17:24
html with clean body
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
</html>