Skip to content

Instantly share code, notes, and snippets.

View aldarund's full-sized avatar
🎯
Focusing

Dmitry Molotkov aldarund

🎯
Focusing
View GitHub Profile
@nabilfreeman
nabilfreeman / lambda-redirect-to-trailing-slash.js
Last active March 7, 2023 20:31
Redirect to trailing slashes on CloudFront with AWS Lambda. (all this because S3 uses 302 redirects instead of 301)
'use strict';
const path = require('path')
const redirect = new_url => {
return {
status: '301',
statusDescription: 'Moved Permanently',
headers: {
location: [{
@kirilloid
kirilloid / type.js
Last active July 29, 2022 19:42
getType
function getType (value) {
let type = typeof value;
if (type === 'object') {
return value ? Object.prototype.toString.call(value).slice(8, -1) : 'null';
}
return type;
}
[NaN, 0, 1, Infinity, // numbers
null, undefined, false, 'str', // other primitives
@erans
erans / gmail_email.py
Created July 17, 2011 07:45
Check if an Email address is Gmail or Google Apps for your domain
import sys
import re
import dns.resolver # Requires dnspython
email_host_regex = re.compile(".*@(.*)$")
gmail_servers_regex = re.compile("(.google.com.|.googlemail.com.)$", re.IGNORECASE)
def is_gmail(email):
""" Returns True if the supplied Email address is a @gmail.com Email or is a Google Apps for your domain - hosted Gmail address
Checks are performed by checking the DNS MX records """
@ssbarnea
ssbarnea / mysql-convert-utf8.py
Created July 6, 2011 18:48
Script to convert a a database to use utf8 encoding
#! /usr/bin/env python
import MySQLdb
host = "localhost"
passwd = ""
user = "root"
dbname = "mydbname"
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=dbname)
cursor = db.cursor()
@debrouwere
debrouwere / gist:809993
Created February 3, 2011 19:20
Nested resources in django-tastypie
from sandbox import models
from tastypie import fields
from apibase.resources import CamayakModelResource
from django.conf.urls.defaults import url
class ModelResource(CamayakModelResource):
def override_urls(self):
urls = []
for name, field in self.fields.items():