Skip to content

Instantly share code, notes, and snippets.

@cosbgn
cosbgn / Find if your user is in the EU (Geolocation api javascript)
Created November 11, 2019 11:56
Find if user is in the EU without any extra API or server-side code or IP Address
// You can easily find out if the user is in the EU calculating the offset from GMT.
// It's not a perfect method but for simple use cases it works perfectly
// It also catches all Africa
const offset = new Date().getTimezoneOffset();
// 0 is GMT and - 120 is Finland -
// It should catch all the EU - However it also catches most of Africa so use it carefully!
@cosbgn
cosbgn / WeatherResponse.json
Last active January 29, 2018 16:58
Open Weather Weather Response
{
"coord":{
"lon":-122.42,
"lat":37.78
},
"weather":[
{
"id":701,
"main":"Mist",
"description":"mist",
@cosbgn
cosbgn / vueLoader.vue
Created October 10, 2017 18:08
Vue.js Loader
<template>
<div>
<div class="spinner">
<div class="cube1"></div>
<div class="cube2"></div>
</div>
<br />
<div class='has-text-centered'>
<p class='subtitle' v-html='msg'></p>
@cosbgn
cosbgn / google_login_oauth2client.py
Created June 10, 2017 20:28
Example of Google oAuth2Client login
# /start
def start_google(request):
"""first step Oauth2 to google analytics and get code"""
flow = OAuth2WebServerFlow(client_id = settings.GOOGLE_OAUTH2_CLIENT_ID,
client_secret = settings.GOOGLE_OAUTH2_CLIENT_SECRET,
scope = settings.GOOGLE_SCOPE,
redirect_uri = settings.OAUTH_REDIRECT_URI,
access_type='offline',
)
auth_uri = flow.step1_get_authorize_url()
/* Enter Your Custom Functions Here */
// Add custom validation for CF7 form fields
function is_company_email($email){ // Check against list of common public email providers & return true if the email provided *doesn't* match one of them
if(
preg_match('/@gmail./i', $email) ||
preg_match('/@hotmail./i', $email) ||
preg_match('/@live./i', $email) ||
preg_match('/@msn./i', $email) ||
preg_match('/@aol./i', $email) ||