Skip to content

Instantly share code, notes, and snippets.

View dphans's full-sized avatar
🚀
Usually respond within a day

Bao Phan dphans

🚀
Usually respond within a day
View GitHub Profile
@iamriajul
iamriajul / ConnectivityUtil.kt
Created April 26, 2021 05:19
Android Kotlin utility class for checking device's network connectivity and speed and internet availability. - You may use this with DI system easily.
package org.dailyislam.android.utilities
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkInfo
import android.telephony.TelephonyManager
import java.net.InetAddress
class ConnectivityUtil(private val applicationContext: Context) {
@erlingpaulsen
erlingpaulsen / coinbase_profit_loss.py
Created January 15, 2021 12:18
Python script for connecting to your Coinbase account through the API. Used to compute and plot the balance and cost per wallet and in total, in addition to calculate the total profit/loss. Will calculate to your native currency.
import json, hmac, hashlib, time, requests
import numpy as np
from requests.auth import AuthBase
import matplotlib.pyplot as plt
# Name of account holder (only for displaying)
USER = 'My name'
# API key and secret. Create these in your Coinbase account with all read permissions selected for all accounts
API_KEY = 'xxx'
@ConfidenceYobo
ConfidenceYobo / django-git-workflow.md
Last active March 25, 2024 23:04
Setting up Git workflow for django

Setup Github Actions for Django Project

Step 1

In project root directory the create a folder called '.github'

Step 2

Create a file in the format workflows/django.yml

@mhewedy
mhewedy / Main.kt
Last active February 14, 2023 15:10
Kotlin X509 certificate + PEM private key : encryption and decryption
/**
depends on config from https://www.baeldung.com/java-bouncy-castle
*/
import org.bouncycastle.cms.*
import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder
import org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient
import org.bouncycastle.cms.jcajce.JceKeyTransRecipientInfoGenerator
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.util.encoders.Base64
@npearce
npearce / install-docker.md
Last active April 19, 2024 12:35
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command

UPDATE (March 2020, thanks @ic): I don't know the exact AMI version but yum install docker now works on the latest Amazon Linux 2. The instructions below may still be relevant depending on the vintage AMI you are using.

Amazon changed the install in Linux 2. One no-longer using 'yum' See: https://aws.amazon.com/amazon-linux-2/release-notes/

Docker CE Install

sudo amazon-linux-extras install docker
sudo service docker start
@nickbutcher
nickbutcher / MainActivity.kt
Last active February 22, 2024 21:17
Demonstrating how to tile a (Vector) Drawable
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@mihow
mihow / load_dotenv.sh
Last active May 4, 2024 12:32
Load environment variables from dotenv / .env file in Bash
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
@languanghao
languanghao / left-bar.vue
Created December 22, 2016 06:56
element ui menu with vue-router
<template>
<el-menu :router="true" :default-active="activeLink">
<template v-for="rule in $router.options.routes">
<el-submenu v-if="rule.children && rule.children.length > 0"
:index="rule.path"
>
<template slot="title"><i :class="rule.icon"></i>{{ rule.title }}</template>
<el-menu-item v-for="child in rule.children" :index="rule.path + '/' + child.path">{{ child.title }}</el-menu-item>
</el-submenu>
<el-menu-item v-else
@sorenlouv
sorenlouv / signed_request.js
Created January 3, 2016 00:31
Parse signed request from Facebook cookie, and exchange code to access token
var request = require('request-promise');
var crypto = require('crypto');
var config = {...};
function getAccessToken(cookies) {
var cookieName = 'fbsr_' + config.client_id;
var signedRequest = cookies[cookieName];
var code = getCode(signedRequest);
return exchangeCodeForAccessToken(code);
};
def nearby_spots_old(request, lat, lng, radius=5000, limit=50):
"""
WITHOUT use of any external library, using raw MySQL and Haversine Formula
http://en.wikipedia.org/wiki/Haversine_formula
"""
radius = float(radius) / 1000.0
query = """SELECT id, (6367*acos(cos(radians(%2f))
*cos(radians(latitude))*cos(radians(longitude)-radians(%2f))
+sin(radians(%2f))*sin(radians(latitude))))