Skip to content

Instantly share code, notes, and snippets.

View Pygmalion69's full-sized avatar

Serge Helfrich Pygmalion69

View GitHub Profile
@Pygmalion69
Pygmalion69 / exercise-reader.go
Created February 29, 2020 16:08
A Tour of Go - Exercise: Reader
// https://tour.golang.org/methods/22
package main
import "golang.org/x/tour/reader"
type MyReader struct{}
func (r MyReader) Read(b []byte) (int, error) {
for i := range b {
b[i] = 65
@Pygmalion69
Pygmalion69 / exercise-errors.go
Last active February 29, 2020 14:45
A Tour of Go - Exercise: Errors
// https://tour.golang.org/methods/20
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
@Pygmalion69
Pygmalion69 / exercise-stringer.go
Created February 29, 2020 14:13
A Tour of Go - Exercise: Stringers
// https://tour.golang.org/methods/18
package main
import "fmt"
type IPAddr [4]byte
func (ip IPAddr) String() string {
return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
}
@Pygmalion69
Pygmalion69 / exercise-fibonacci-closure.go
Last active February 28, 2020 18:26
A Tour of Go - Exercise: Fibonacci closure
// https://tour.golang.org/moretypes/26
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a, b := 1, 0
return func() int {
@Pygmalion69
Pygmalion69 / exercise-maps.go
Created February 28, 2020 15:31
A Tour of Go - Exercise: Maps
// https://tour.golang.org/moretypes/23
package main
import (
"strings"
"golang.org/x/tour/wc"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
@Pygmalion69
Pygmalion69 / exercise-slices.go
Created February 28, 2020 14:27
A Tour of Go - Exercise: Slices
// https://tour.golang.org/moretypes/18
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for y := range pic {
pic[y] = make([]uint8, dx)
for x := range pic[y] {
/* Govern ancient Sumeria. Heavily modified by Mike Arnautov 1975.
* Converted from Basic to PR1ME Fortran (mode 32R) MLA 1979.
* Rev.19.1, GGR version 14 Oct 83. MLA
* Converted to ANSI C December 2001. MLA
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
/**
* Lock the screen to the current orientation on Android
* https://stackoverflow.com/questions/4553650/how-to-check-device-natural-default-orientation-on-android-i-e-get-landscape
* https://stackoverflow.com/a/14150037/959505
*
*/
private void lockOrientation() {
int orientation = 0;
WindowManager windowService = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
if (windowService != null) {
@Pygmalion69
Pygmalion69 / .travis.yml
Created January 18, 2018 13:08
Android .travis.yml
language: android
android:
components:
- tools # to get the new `repository-11.xml`
- tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943)
- platform-tools
- build-tools-26.0.2
- android-22
- android-26
@Pygmalion69
Pygmalion69 / .travis.yml
Created January 18, 2018 13:06
.travis.yml by BanzaiMan
language: android
jdk: oraclejdk8
#sudo: false
android:
components:
# Uncomment the lines below if you want to
# use the latest revision of Android SDK Tools
- tools