Skip to content

Instantly share code, notes, and snippets.

View hcz's full-sized avatar
🔥

Serge Osipov hcz

🔥
View GitHub Profile
@hcz
hcz / caesar-cypher.js
Last active January 13, 2018 00:34
Caesar's cipher, the shift cipher
const shift = (cypherShift, alphabet, messageChar) => {
const charCode = (ch) => ch.toLowerCase().charCodeAt(0);
let begin = charCode(alphabet.from);
let end = charCode(alphabet.to);
[begin, end] = (begin > end) ? [end, begin] : [begin, end];
const alphabetLength = end - begin;
const shiftLength = cypherShift % alphabetLength;
if (alphabetLength === 0) return messageChar;
@hcz
hcz / cdn-from-console.js
Last active September 22, 2018 13:11
Adds scripts from CDN in browser console or via bookmarklet
/**
* Adds scripts on page without CORS to use additional scripts from CDN
* Creates scripts inside <head> tag
*
* @license MIT
* @copyright Sergei Osipov 2017
*/
((cdnList) => {
cdnList
@hcz
hcz / cors.nginxconf
Created January 14, 2019 20:41 — forked from pauloricardomg/cors.nginxconf
Nginx configuration for CORS-enabled HTTPS proxy with origin white-list defined by a simple regex
#
# Acts as a nginx HTTPS proxy server
# enabling CORS only to domains matched by regex
# /https?://.*\.mckinsey\.com(:[0-9]+)?)/
#
# Based on:
# * http://blog.themillhousegroup.com/2013/05/nginx-as-cors-enabled-https-proxy.html
# * http://enable-cors.org/server_nginx.html
#
server {
@hcz
hcz / btoa-atob.js
Created March 5, 2019 12:02
Node.js ponyfill for atob and btoa
const atob = a => new Buffer(a, 'base64').toString('binary');
const btoa = b => new Buffer(b).toString('base64');
@hcz
hcz / react.html
Created May 5, 2021 20:23
React + babel + JSX inside a single HTML file
<html>
<head>
<meta charSet="utf-8">
<title>Hello world</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.0/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@17.0.0/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js">
</script>
</head>
<body>