Skip to content

Instantly share code, notes, and snippets.

View NRDeshpande's full-sized avatar
:octocat:
In search of private jets

Nikhil Deshpande NRDeshpande

:octocat:
In search of private jets
  • Building Products
  • Berlin & Bengaluru
View GitHub Profile
@NRDeshpande
NRDeshpande / csrf.js
Created February 21, 2020 10:58 — forked from danielbeardsley/csrf.js
Dynamically add CSRF protection <input>s to each form on the page immediately before it's submitted. This code uses MooTools, though it would be trivial to remove that dependency or swap with jQuery.
var CSRF = (function() {
window.addEvent('domready', function() {
/**
* Setup triggers on the .submit() function and the `submit` event so we
* can add csrf inputs immediately before the form is submitted.
*/
$$('form').each(function(form) {
// Ensure all forms submitted via a traditional 'submit' button have
// an up-to-date CSRF input
form.addEvent('submit', function() {
@NRDeshpande
NRDeshpande / nginx.conf
Last active February 7, 2019 12:53 — forked from Stanback/nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your **location** block(s):
#
# include cors_support;
#
# As of Nginx 1.7.5, add_header supports an "always" parameter which
@NRDeshpande
NRDeshpande / calculate-utc-offset-dst.php
Created January 30, 2019 06:35 — forked from glueckpress/calculate-utc-offset-dst.php
Calculate a timezone’s offset to UTC considering daylight savings time (e.g. CEST), print a string like “UTC+2” or “UTC-9”
<?php
/**
* Prints a string showing current time zone offset to UTC, considering daylight savings time.
* @link http://php.net/manual/en/timezones.php
* @param string $time_zone Time zone name
* @return string Offset in hours, prepended by +/-
*/
function ch150918__utc_offset_dst( $time_zone = 'Europe/Berlin' ) {
// Set UTC as default time zone.