Skip to content

Instantly share code, notes, and snippets.

View regex-weburl.js
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//
@jftuga
jftuga / HaversinFormula.go
Created Sep 16, 2021 — forked from cdipaolo/HaversinFormula.go
Golang functions to calculate the distance in meters between long,lat points on Earth.
View HaversinFormula.go
// haversin(θ) function
func hsin(theta float64) float64 {
return math.Pow(math.Sin(theta/2), 2)
}
// Distance function returns the distance (in meters) between two points of
// a given longitude and latitude relatively accurately (using a spherical
// approximation of the Earth) through the Haversin Distance Formula for
// great arc distance on a sphere with accuracy for small distances
//
@jftuga
jftuga / default_gateway.go
Created Aug 12, 2021 — forked from abimaelmartell/default_gateway.go
Get default gateway by parsing RIB information using the net/route package. BSD Only.
View default_gateway.go
package main
import (
"fmt"
"golang.org/x/net/route"
)
var defaultRoute = [4]byte{0, 0, 0, 0}
func main() {
@jftuga
jftuga / *pycharm-setup-2020.3.2.md
Created Jun 18, 2021 — forked from rszeto/*pycharm-setup-2020.3.2.md
Setting up PyCharm project with remote interpreter
View *pycharm-setup-2020.3.2.md

Setting up PyCharm project with remote interpreter

Setting up a remote interpreter on PyCharm is awfully unintuitive. I've pared it down to what I think is the minimal number of steps, and leaves the fewest number of deployment configurations and Python interpreters lying around. This is designed for my specific configuration (specifically PyTorch); adapt as needed.

Configuring default project (only do after installing PyCharm for the first time):

  1. (Optional) Add virtual environment path to excluded files
    1. From Welcome Page, go to Configure > Settings > Build, Execution, Deployment > Deployment > Options
    2. Add virtualenv path. For example, if you always have the project's virtualenv in .env, add ";.env" to the "Exclude items by name" field
@jftuga
jftuga / set_outer_border_for_range_xlsx.py
Created May 28, 2021 — forked from pankaj28843/set_outer_border_for_range_xlsx.py
A simple hack - set outer border for a range using xlsxwriter, a Python library
View set_outer_border_for_range_xlsx.py
from __future__ import absolute_import
try:
import cStringIO as StringIO
except ImportError:
import StringIO
# Standard Library
import re
import string
@jftuga
jftuga / upsert.py
Created May 19, 2021 — forked from bhtucker/upsert.py
A demonstration of Postgres upserts in SQLAlchemy
View upsert.py
"""
Upsert gist
Requires at least postgres 9.5 and sqlalchemy 1.1
Initial state:
[]
Initial upsert:
@jftuga
jftuga / sqlalchemy_upsert.py
Created May 19, 2021 — forked from malexer/sqlalchemy_upsert.py
Modelling UPSERT in SQLAlchemy (well actually it is not upsert but speed improvement is significant in comparison with simple session.merge)
View sqlalchemy_upsert.py
# Note: it is a copy of great answer by "mgoldwasser" from Stackoverflow
# Check the original answer here: http://stackoverflow.com/a/26018934/1032439
# Imagine that post1, post5, and post1000 are posts objects with ids 1, 5 and 1000 respectively
# The goal is to "upsert" these posts.
# we initialize a dict which maps id to the post object
my_new_posts = {1: post1, 5: post5, 1000: post1000}
for each in posts.query.filter(posts.id.in_(my_new_posts.keys())).all():
@jftuga
jftuga / app.py
Created May 19, 2021 — forked from DmitryBe/app.py
SQLAlchemy quick start
View app.py
# http://bytefish.de/blog/first_steps_with_sqlalchemy/
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from datetime import datetime, timedelta
from sqlalchemy import Table, Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.orm import relationship, backref
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
@jftuga
jftuga / MyViewController.cs
Created Jan 28, 2021 — forked from ShayMe21/MyViewController.cs
Xamarin with Auth0 and TouchID Authentication
View MyViewController.cs
// https://github.com/auth0-community/auth0-xamarin-oidc-samples/tree/master/Quickstart/01-Login/iOS
using System;
using UIKit;
using Auth0.OidcClient;
using System.Text;
using LocalAuthentication;
using Foundation;
using Xamarin.Auth;
@jftuga
jftuga / go-os-arch.md
Created Dec 4, 2020 — forked from asukakenji/0-go-os-arch.md
Go (Golang) GOOS and GOARCH
View go-os-arch.md

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.14.7 darwin/amd64.

A list of valid GOOS values

(Bold = supported by go out of the box, ie. without the help of a C compiler, etc.)

  • aix
  • android