Skip to content

Instantly share code, notes, and snippets.

View oyamo's full-sized avatar
🏠
Working from home

Oyamo Brian oyamo

🏠
Working from home
View GitHub Profile
package main
import (
"github.com/go-co-op/gocron"
"time"
)
func ScheduleTask(quit chan bool, seconds int, task func()) {
s := gocron.NewScheduler(time.UTC)
// Quit the scheduler when the quit channel is returns true
@oyamo
oyamo / GoConcurrency.md
Created April 4, 2021 07:41 — forked from rushilgupta/GoConcurrency.md
Concurrency in golang and a mini Load-balancer

INTRO

Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".

Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).

Let's dig in:

Goroutines

@oyamo
oyamo / header_http_status_codes.php
Created April 27, 2019 08:31 — forked from phoenixg/header_http_status_codes.php
PHP header() for sending HTTP status codes
<?php
/*
参考自:
http://darklaunch.com/2010/09/01/http-status-codes-in-php-http-header-response-code-function
http://snipplr.com/view/68099/
*/
function HTTPStatus($num) {
$http = array(
<select>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antartica">Antarctica</option>
<option value="Antigua and Barbuda">Antigua and Barbuda</option>
double mLatitude = 0.0;
double mLongitude = 0.0;
private FusedLocationProviderClient mFusedLocationClient;
// mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
// ^ to be instatiated inside onCreate method
public void fetchGPS() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;