Skip to content

Instantly share code, notes, and snippets.

View astranavt's full-sized avatar
🌴
On vacation

Anton astranavt

🌴
On vacation
View GitHub Profile
@michiel
michiel / cors-nginx.conf
Created July 5, 2011 10:41
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@realmyst
realmyst / gist:1262561
Created October 4, 2011 19:34
Склонение числительных в javascript
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
use:
declOfNum(count, ['найдена', 'найдено', 'найдены']);
@githiro
githiro / gist:5819142
Created June 19, 2013 23:45
JS: forEach polyfill
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fn, scope)
{
for(var i = 0, len = this.length; i < len; ++i)
{
fn.call(scope, this[i], i, this);
}
}
}
@soheilhy
soheilhy / nginxproxy.md
Last active May 16, 2024 08:59
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@hufyhang
hufyhang / forEach.js
Created December 27, 2015 15:33
JavaScript Array.prototype.forEach Polyfill
/*
* forEach Polyfill
*
* 2015-12-27
*
* By Feifei Hang, http://feifeihang.info
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
'use strict';
@pirate
pirate / parseURLParameters.js
Last active December 15, 2023 07:17
Parse URL query parameters in ES6
function getUrlParams(search) {
const hashes = search.slice(search.indexOf('?') + 1).split('&')
const params = {}
hashes.map(hash => {
const [key, val] = hash.split('=')
params[key] = decodeURIComponent(val)
})
return params
}
@saulshanabrook
saulshanabrook / README.md
Created October 19, 2016 14:20
Saving Web Crypto Keys using indexedDB

This is a working example on how to store CryptoKeys locally in your browser. We are able to save the objects, without serializing them. This means we can keep them not exportable (which might be more secure?? not sure what attack vectors this prevents).

To try out this example, first make sure you are in a browser that has support for async...await and indexedDB (latest chrome canary with chrome://flags "Enable Experimental Javascript" works). Load some page and copy and paste this code into the console. Then call encryptDataSaveKey(). This will create a private/public key pair and encrypted some random data with the private key. Then save both of them. Now reload the page, copy in the code, and run loadKeyDecryptData(). It will load the keys and encrypted data and decrypt it. You should see the same data logged both times.

@zmts
zmts / tokens.md
Last active June 11, 2024 08:13
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
@jaredpalmer
jaredpalmer / withSSR.js
Last active August 1, 2019 00:40
SSR HOC
import React from 'react';
import axios from 'axios';
// This is a Higher Order Component that abstracts duplicated data fetching
// on the server and client.
export default function SSR(Page) {
class SSR extends React.Component {
static getInitialData(ctx) {
// Need to call the wrapped components getInitialData if it exists
return Page.getInitialData
@YozhEzhi
YozhEzhi / async\await и циклы.txt
Last active June 2, 2021 09:29
Анти-паттерн: async/await и циклы.
Рассмотрим перебор массива с коллбэком:
const BEATLES = ['john', 'paul', 'george', 'ringo'];
// Обычный цикл for:
for (let i = 0; i < BEATLES.length; ++i) {
console.log(BEATLES[i]);
}
// Метод Array.forEach:
BEATLES.forEach(beatle => console.log(beatle));