file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
tests/karma.conf.js
JavaScript
module.exports = function(config) { config.set({ frameworks: ['qunit'], basePath: '.', files: [ '../index.js', '../tests/tests.js' ], singleRun: false, }); };
zloirock/dtf
42
Date formatting
JavaScript
zloirock
Denis Pushkarev
tests/tests.html
HTML
<!DOCTYPE html> <meta charset='UTF-8'> <title>dtf</title> <link rel='stylesheet' href='https://code.jquery.com/qunit/qunit-1.16.0.css'> <div id='qunit'></div> <div id='qunit-fixture'></div> <script src='https://code.jquery.com/qunit/qunit-1.16.0.js'></script> <script src='../index.js'></script> <script src='./tests.js'...
zloirock/dtf
42
Date formatting
JavaScript
zloirock
Denis Pushkarev
tests/tests.js
JavaScript
var date = new Date(1, 2, 3, 4, 5, 6, 7); function isFunction(it){ return {}.toString.call(it).slice(8, -1) === 'Function'; } QUnit.test('dtf.locale', function(assert){ assert.ok(isFunction(dtf.locale), 'Is function'); dtf.locale('en'); assert.strictEqual(dtf.locale(), 'en', '.locale() is "en"'); assert.stri...
zloirock/dtf
42
Date formatting
JavaScript
zloirock
Denis Pushkarev
index.mjs
JavaScript
import { basename } from 'node:path'; const meta = { type: 'layout', docs: { description: 'ensure that filenames match a convention', }, messages: { noMatch: 'Filename `{{name}}` does not match {{value}}', }, fixable: false, schema: false, }; function create(context) { return { Program(nod...
zloirock/eslint-plugin-name
0
JavaScript
zloirock
Denis Pushkarev
lib/components/godoc-panel-view.js
JavaScript
/** @babel */ /** @jsx etch.dom */ import etch from 'etch' export default class GodocPanelView { constructor (props) { if (props.model) { props.model.view = this } this.props = props etch.initialize(this) etch.setScheduler(atom.views) } update (props) { let oldProps = this.props...
zmb3/godoc
3
Deprecated - use https://atom.io/packages/go-plus instead
JavaScript
zmb3
Zac Bergquist
gravitational
lib/godoc-panel.js
JavaScript
'use babel' import {CompositeDisposable} from 'atom' export default class GodocPanel { constructor (goconfigFunc) { this.key = 'reference' this.subscriptions = new CompositeDisposable() let keymap = 'alt-d' let bindings = atom.keymaps.findKeyBindings({command: 'golang:showdoc'}) if (bindings &&...
zmb3/godoc
3
Deprecated - use https://atom.io/packages/go-plus instead
JavaScript
zmb3
Zac Bergquist
gravitational
lib/godoc.js
JavaScript
'use babel' import path from 'path' import {CompositeDisposable, Point} from 'atom' import GodocPanel from './godoc-panel' class Godoc { constructor (goconfigFunc, gogetFunc) { this.goconfig = goconfigFunc this.goget = gogetFunc this.subscriptions = new CompositeDisposable() this.panelModel = new Go...
zmb3/godoc
3
Deprecated - use https://atom.io/packages/go-plus instead
JavaScript
zmb3
Zac Bergquist
gravitational
lib/main.js
JavaScript
'use babel' import {CompositeDisposable} from 'atom' import {Godoc} from './godoc' import GodocPanelView from './components/godoc-panel-view' export default { subscriptions: null, dependenciesInstalled: null, goconfig: null, goget: null, godoc: null, toolRegistered: null, activate () { this.godoc =...
zmb3/godoc
3
Deprecated - use https://atom.io/packages/go-plus instead
JavaScript
zmb3
Zac Bergquist
gravitational
spec/fixtures/main.go
Go
package main import ( "fmt" "io" "os" "strings" ) // Foo has a message. type Foo struct { // Message is a test message. Message string } // ChangeMessage changes the Foo's message. func (f *Foo) ChangeMessage(msg string) { f.Message = msg } func main() { fmt.Println("Hello, World") f := &Foo{"This is a tes...
zmb3/godoc
3
Deprecated - use https://atom.io/packages/go-plus instead
JavaScript
zmb3
Zac Bergquist
gravitational
spec/godoc-spec.js
JavaScript
'use babel' /* eslint-env jasmine */ import temp from 'temp' import path from 'path' import fs from 'fs-plus' describe('godoc', () => { temp.track() let mainModule = null let godoc = null let editor = null let gopath = null let oldGopath = null let source = null let target = null beforeEach(() => {...
zmb3/godoc
3
Deprecated - use https://atom.io/packages/go-plus instead
JavaScript
zmb3
Zac Bergquist
gravitational
spec/main-spec.js
JavaScript
'use babel' /* eslint-env jasmine */ describe('godoc', () => { let mainModule = null beforeEach(() => { waitsForPromise(() => { return atom.packages.activatePackage('go-config').then(() => { return atom.packages.activatePackage('godoc') }).then((pack) => { mainModule = pack.mainMod...
zmb3/godoc
3
Deprecated - use https://atom.io/packages/go-plus instead
JavaScript
zmb3
Zac Bergquist
gravitational
styles/godoc.less
LESS
.godoc-panel { white-space: pre-wrap; }
zmb3/godoc
3
Deprecated - use https://atom.io/packages/go-plus instead
JavaScript
zmb3
Zac Bergquist
gravitational
builtin.go
Go
package main import ( "go/ast" "go/doc" "go/parser" "go/token" "go/types" "log" "golang.org/x/tools/go/packages" ) func builtinPackage() *doc.Package { pkgs, err := packages.Load(&packages.Config{Mode: packages.LoadFiles}, "builtin") if err != nil { log.Fatalf("error getting metadata of builtin: %v", err)...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
doc.go
Go
package main import ( "bytes" "fmt" "go/doc" ) const ( indent = "" preIndent = " " ) // Doc holds the resulting documentation for a particular item. type Doc struct { Name string `json:"name"` Import string `json:"import"` Pkg string `json:"pkg"` Decl string `json:"decl"` Doc string `json:"...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
ident.go
Go
package main import ( "bytes" "fmt" "go/ast" "go/printer" "go/token" "go/types" "strings" "golang.org/x/tools/go/ast/astutil" "golang.org/x/tools/go/packages" ) func findTypeSpec(decl *ast.GenDecl, pos token.Pos) *ast.TypeSpec { for _, spec := range decl.Specs { typeSpec := spec.(*ast.TypeSpec) if type...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
ident_test.go
Go
package main import ( "go/token" "path/filepath" "runtime" "strings" "testing" "golang.org/x/tools/go/packages/packagestest" ) func TestIdent(t *testing.T) { dir := filepath.Join(".", "testdata", "package") mods := []packagestest.Module{ {Name: "somepkg", Files: packagestest.MustCopyFileTree(dir)}, } pa...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
main.go
Go
// gogetdoc gets documentation for Go objects given their locations in the source code package main import ( "encoding/json" "errors" "flag" "fmt" "go/ast" "go/build" "go/parser" "go/token" "io" "io/ioutil" "log" "os" "runtime/debug" "runtime/pprof" "strconv" "strings" "golang.org/x/tools/go/ast/ast...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
main_test.go
Go
package main import ( "go/token" "os" "path/filepath" "runtime" "strconv" "strings" "testing" "golang.org/x/tools/go/packages" "golang.org/x/tools/go/packages/packagestest" ) func TestParseValidPos(t *testing.T) { fname, offset, err := parsePos("foo.go:#123") if fname != "foo.go" { t.Errorf("want foo.go...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
modified_test.go
Go
package main import ( "fmt" "path/filepath" "runtime" "strings" "testing" "golang.org/x/tools/go/buildutil" "golang.org/x/tools/go/packages/packagestest" ) const contents = `package somepkg import "fmt" const ( Zero = iota One Two ) const Three = 3 func main() { fmt.Println(Zero, Three, Two, Three) } ` ...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
pkg.go
Go
package main import ( "errors" "fmt" "go/ast" "go/doc" "golang.org/x/tools/go/packages" ) // ImportPath gets the import path from an ImportSpec. func ImportPath(is *ast.ImportSpec) string { s := is.Path.Value l := len(s) // trim the quotation marks return s[1 : l-1] } // PackageDoc gets the documentation f...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
pkg_test.go
Go
package main import ( "go/token" "path/filepath" "runtime" "strings" "testing" "golang.org/x/tools/go/packages/packagestest" ) func TestPackageDoc(t *testing.T) { dir := filepath.Join(".", "testdata", "package-doc") mods := []packagestest.Module{ {Name: "pkgdoc", Files: packagestest.MustCopyFileTree(dir)},...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/interface-decls/rabbit.go
Go
package rabbit type Thing interface { Do(s Stuff) Stuff //@decl("Do", "func (Thing).Do(s Stuff) Stuff") DoWithError(s Stuff) (Stuff, error) //@decl("hError", "func (Thing).DoWithError(s Stuff) (Stuff, error)") DoWithNoArgs() //@decl("WithNoArgs", "func (Thing).DoWithNoArgs(...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/issue52/first/first.go
Go
package first import "issue52/first/second" //V this works var V second.T
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/issue52/first/second/second.go
Go
package second type T struct{} //Foo this doesn't work but should func (t T) Foo() {}
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/issue52/main.go
Go
package main import ( "issue52/first" ) func main() { first.V.Foo() }
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/package-doc/main.go
Go
// LICENSE TEXT // Package main is an example package. package main // superfluous comment import ( "fmt" mth "math" //@pkgdoc("th", "Package math provides"), pkgdoc("ath", "Package math provides") ) func main() { fmt.Println(mth.IsNaN(1.23)) //@pkgdoc("th.IsNaN", "Package math provides") fmt.Println("Goodbye")...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/package/const.go
Go
package somepkg import "fmt" const ( Zero = iota One Two ) const Three = 3 func main() { fmt.Println(Zero, One, Two, Three) //@const("Zero", "0"), const("One", "1"), const("Three", "3") }
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/package/embed.go
Go
package somepkg // foo doc type foo struct { i int } type bar1 struct { foo //@doc("foo", "foo doc"), pkg("foo", "somepkg") f1 foo } type bar2 struct { *foo //@doc("foo", "foo doc"), pkg("foo", "somepkg") f1 *foo //@doc("foo", "foo doc"), pkg("foo", "somepkg") }
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/package/idents.go
Go
package somepkg import ( "fmt" mth "math" ) type X struct{} // SayHello says hello. func (X) SayHello() { fmt.Println("Hello, World", mth.IsNaN(1.23)) //@doc("IsNaN", "IsNaN reports whether f") } func Baz() { var x X //@decl("X", "type X struct{}") x.SayHello() //@decl("ayHello", "func (X) SayHello()") S...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/package/issue20.go
Go
package somepkg import "fmt" // Foo is a test function. func Foo() { words := []string{} for _, word := range words { //@decl("rds", "var words []string") fmt.Println(word) } } func Bar() { tests := []struct { Name string args string }{ {"Test1", "a b c"}, {"Test2", "a b c"}, } for _, test := range ...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
testdata/withvendor/main.go
Go
package main import ( "fmt" "github.com/zmb3/vp" //@import(".com", "github.com/zmb3/vp"), decl(".com", "package vp") ) func main() { vp.Hello() //@import("ello", "github.com/zmb3/vp"), doc("ello", "Hello says hello.\n") fmt.Println(vp.Foo) //@decl("Foo", "const Foo untyped string") }
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
unexported.go
Go
package main import ( "fmt" "go/ast" "log" "unicode" "unicode/utf8" ) // Note: the code in this file is borrowed from the Go project. // It is licensed under a BSD-style license that is available // at https://golang.org/LICENSE. // // Copyright 2015 The Go Authors. All rights reserved. // Use of this source cod...
zmb3/gogetdoc
185
Gets documentation for items in Go source code.
Go
zmb3
Zac Bergquist
gravitational
Hexdump.hpp
C++ Header
#ifndef HEXDUMP_HPP #define HEXDUMP_HPP #include <cctype> #include <iomanip> #include <ostream> template <unsigned RowSize, bool ShowAscii> struct CustomHexdump { CustomHexdump(const void* data, unsigned length) : mData(static_cast<const unsigned char*>(data)), mLength(length) { } const unsigned char*...
zmb3/hexdump
63
A header-only utility for writing hexdump-formatted data to C++ streams.
C++
zmb3
Zac Bergquist
gravitational
example.cpp
C++
#include "Hexdump.hpp" #include <iostream> int main() { unsigned char data[150]; unsigned char c = 0; for (auto& val : data) { val = c++; } std::cout << Hexdump(data, sizeof(data)) << std::endl; std::cout << CustomHexdump<8, true>(data, sizeof(data)) << std::endl; std::cout <<...
zmb3/hexdump
63
A header-only utility for writing hexdump-formatted data to C++ streams.
C++
zmb3
Zac Bergquist
gravitational
cmd/client/client.go
Go
// Command client is used to test the behavior of a TCP // load balancer. It assumes that the load balancer fronts // one or more TCP echo servers, like the ones found in // commmand upstreams. package main import ( "bytes" "crypto/tls" "crypto/x509" "errors" "flag" "fmt" "log" "math/rand" "net" "os" "strco...
zmb3/lbtest
0
Go
zmb3
Zac Bergquist
gravitational
cmd/upstreams/upstreams.go
Go
// Command upstreams runs one or more "upstreams" that // can sit behind a load balancer, and tracks the number // connections each has received. package main import ( "context" "flag" "fmt" "io" "log" "net" "os" "os/signal" "sync/atomic" ) func main() { count := flag.Int("n", 1, "the number of upstreams to...
zmb3/lbtest
0
Go
zmb3
Zac Bergquist
gravitational
album.go
Go
package spotify import ( "context" "errors" "fmt" "strconv" "strings" "time" ) // SimpleAlbum contains basic data about an album. type SimpleAlbum struct { // The name of the album. Name string `json:"name"` // A slice of [SimpleArtist]. Artists []SimpleArtist `json:"artists"` // The field is present when ...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
album_test.go
Go
package spotify import ( "context" "net/http" "testing" ) // The example from https://developer.spotify.com/web-api/get-album/ func TestFindAlbum(t *testing.T) { client, server := testClientFile(http.StatusOK, "test_data/find_album.txt") defer server.Close() album, err := client.GetAlbum(context.Background(), ...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
artist.go
Go
package spotify import ( "context" "fmt" "strings" ) // SimpleArtist contains basic info about an artist. type SimpleArtist struct { Name string `json:"name"` ID ID `json:"id"` // The Spotify URI for the artist. URI URI `json:"uri"` // A link to the Web API endpoint providing full details of the artist....
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
artist_test.go
Go
// Copyright 2014, 2015 Zac Bergquist // // 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...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
audio_analysis.go
Go
package spotify import ( "context" "fmt" ) // AudioAnalysis contains a [detailed audio analysis] for a single track // identified by its unique [Spotify ID]. // // [detailed audio analysis]: https://developer.spotify.com/documentation/web-api/reference/get-audio-analysis // [Spotify ID]: https://developer.spotify.c...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
audio_analysis_test.go
Go
package spotify import ( "context" "net/http" "reflect" "testing" ) const fieldsDifferTemplate = "Actual response is not the same as expected response on field %s" var expected = AudioAnalysis{ Bars: []Marker{ { Start: 251.98282, Duration: 0.29765, Confidence: 0.652, }, }, Beats: []Marker{...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
audio_features.go
Go
package spotify import ( "context" "fmt" "strings" ) // AudioFeatures contains various high-level acoustic attributes // for a particular track. type AudioFeatures struct { // Acousticness is a confidence measure from 0.0 to 1.0 of whether // the track is acoustic. A value of 1.0 represents high confidence // ...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
audio_features_test.go
Go
package spotify import ( "context" "net/http" "testing" ) var response = ` { "audio_features" : [ { "danceability" : 0.808, "energy" : 0.626, "key" : 7, "loudness" : -12.733, "mode" : 1, "speechiness" : 0.168, "acousticness" : 0.00187, "instrumentalness" : 0.159, "liveness" : ...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
auth/auth.go
Go
package spotifyauth import ( "context" "errors" "net/http" "os" "golang.org/x/oauth2" ) const ( // AuthURL is the URL to Spotify Accounts Service's OAuth2 endpoint. AuthURL = "https://accounts.spotify.com/authorize" // TokenURL is the URL to the Spotify Accounts Service's OAuth2 // token endpoint. TokenURL...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
category.go
Go
package spotify import ( "context" "fmt" ) // Category is used by Spotify to tag items in. For example, on the Spotify // player's "Browse" tab. type Category struct { // A link to the Web API endpoint returning full details of the category Endpoint string `json:"href"` // The category icon, in various sizes I...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
category_test.go
Go
package spotify import ( "context" "net/http" "testing" ) func TestGetCategories(t *testing.T) { client, server := testClientString(http.StatusOK, getCategories) defer server.Close() page, err := client.GetCategories(context.Background()) if err != nil { t.Fatal(err) } if l := len(page.Categories); l != 2...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
countries.go
Go
package spotify // [ISO 3166-1 alpha-2] country codes. // // [ISO 3166-1 alpha-2]: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 const ( CountryArgentina = "AR" CountryAustralia = "AU" CountryAustria = "AT" CountryBelarus = "BY" CountryBelgium = "BE" CountryB...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
cursor.go
Go
package spotify // This file contains the types that implement Spotify's cursor-based // paging object. Like the standard paging object, this object is a // container for a set of items. Unlike the standard paging object, a // cursor-based paging object does not provide random access to the results. // Cursor contai...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/authenticate/authcode/authenticate.go
Go
// This example demonstrates how to authenticate with Spotify using the authorization code flow. // In order to run this example yourself, you'll need to: // // 1. Register an application at: https://developer.spotify.com/my-applications/ // - Use "http://localhost:8080/callback" as the redirect URI // 2. Set t...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/authenticate/clientcreds/client_credentials.go
Go
// This example demonstrates how to authenticate with Spotify using the // client credentials flow. Note that this flow does not include authorization // and can't be used to access a user's private data. // // Make sure you set the SPOTIFY_ID and SPOTIFY_SECRET environment variables // prior to running this example. ...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/authenticate/pkce/pkce.go
Go
// This example demonstrates how to authenticate with Spotify using the authorization code flow with PKCE. // In order to run this example yourself, you'll need to: // // 1. Register an application at: https://developer.spotify.com/my-applications/ // - Use "http://localhost:8080/callback" as the redirect URI //...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/cli/cli.go
Go
package cli import ( "context" "flag" "github.com/zmb3/spotify/v2" spotifyauth "github.com/zmb3/spotify/v2/auth" "golang.org/x/oauth2" "log" ) var auth = spotifyauth.New(spotifyauth.WithRedirectURL("http://localhost:3000/login_check")) func main() { code := flag.String("code", "", "authorization code to negot...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/features/features.go
Go
package main import ( "context" "fmt" "log" "os" "text/tabwriter" spotifyauth "github.com/zmb3/spotify/v2/auth" "golang.org/x/oauth2/clientcredentials" "github.com/zmb3/spotify/v2" ) func main() { ctx := context.Background() config := &clientcredentials.Config{ ClientID: os.Getenv("SPOTIFY_ID"), ...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/paging/page.go
Go
package main import ( "context" "log" "os" "github.com/zmb3/spotify/v2" spotifyauth "github.com/zmb3/spotify/v2/auth" "golang.org/x/oauth2/clientcredentials" ) func main() { ctx := context.Background() config := &clientcredentials.Config{ ClientID: os.Getenv("SPOTIFY_ID"), ClientSecret: os.Getenv("SP...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/player/player.go
Go
// This example demonstrates how to authenticate with Spotify. // In order to run this example yourself, you'll need to: // // 1. Register an application at: https://developer.spotify.com/my-applications/ // - Use "http://localhost:8080/callback" as the redirect URI // 2. Set the SPOTIFY_ID environment variable...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/profile/profile.go
Go
// Command profile gets the public profile information about a Spotify user. package main import ( "context" "flag" "fmt" spotifyauth "github.com/zmb3/spotify/v2/auth" "log" "os" "golang.org/x/oauth2/clientcredentials" "github.com/zmb3/spotify/v2" ) var userID = flag.String("user", "", "the Spotify user ID ...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/recommendation/recommendation.go
Go
package main import ( "context" "fmt" "log" "os" spotifyauth "github.com/zmb3/spotify/v2/auth" "golang.org/x/oauth2/clientcredentials" "github.com/zmb3/spotify/v2" ) func main() { ctx := context.Background() config := &clientcredentials.Config{ ClientID: os.Getenv("SPOTIFY_ID"), ClientSecret: os.G...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
examples/search/search.go
Go
package main import ( "context" "fmt" spotifyauth "github.com/zmb3/spotify/v2/auth" "log" "os" "golang.org/x/oauth2/clientcredentials" "github.com/zmb3/spotify/v2" ) func main() { ctx := context.Background() config := &clientcredentials.Config{ ClientID: os.Getenv("SPOTIFY_ID"), ClientSecret: os.Ge...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
library.go
Go
package spotify import ( "context" "errors" "fmt" "net/http" "strings" ) // UserHasTracks checks if one or more tracks are saved to the current user's // "Your Music" library. func (c *Client) UserHasTracks(ctx context.Context, ids ...ID) ([]bool, error) { return c.libraryContains(ctx, "tracks", ids...) } // U...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
library_test.go
Go
package spotify import ( "context" "errors" "net/http" "testing" ) func TestUserHasTracks(t *testing.T) { client, server := testClientString(http.StatusOK, `[ false, true ]`) defer server.Close() contains, err := client.UserHasTracks(context.Background(), "0udZHhCi7p1YzMlvI4fXoK", "55nlbqqFVnSsArIeYSQlqx") i...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
page.go
Go
package spotify import ( "context" "errors" "fmt" "reflect" ) // ErrNoMorePages is the error returned when you attempt to get the next // (or previous) set of data but you've reached the end of the data set. var ErrNoMorePages = errors.New("spotify: no more pages") // This file contains the types that implement ...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
page_test.go
Go
package spotify import ( "context" "errors" "github.com/stretchr/testify/assert" "net/http" "testing" ) func TestClient_NextPage(t *testing.T) { testTable := []struct { Name string Input *basePage ExpectedPath string Err error }{ { "success", &basePage{ Next: "/v1/a...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
player.go
Go
package spotify import ( "bytes" "context" "encoding/json" "net/http" "net/url" "strconv" "time" ) // PlayerDevice contains information about a device that a user can play music on. type PlayerDevice struct { // ID of the device. This may be empty. ID ID `json:"id"` // Active If this device is the currently...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
player_test.go
Go
package spotify import ( "context" "net/http" "testing" ) func TestTransferPlaybackDeviceUnavailable(t *testing.T) { client, server := testClientString(http.StatusNotFound, "") defer server.Close() err := client.TransferPlayback(context.Background(), "newdevice", false) if err == nil { t.Error("expected erro...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
playlist.go
Go
package spotify import ( "bytes" "context" "encoding/base64" "encoding/json" "fmt" "io" "net/http" "strconv" "strings" ) // PlaylistTracks contains details about the tracks in a playlist. type PlaylistTracks struct { // A link to the Web API endpoint where full details of // the playlist's tracks can be re...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
playlist_test.go
Go
package spotify import ( "bytes" "context" "encoding/json" "fmt" "io" "net/http" "testing" "time" ) func TestFeaturedPlaylists(t *testing.T) { client, server := testClientFile(http.StatusOK, "test_data/featured_playlists.txt") defer server.Close() country := "SE" msg, p, err := client.FeaturedPlaylists(...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
recommendation.go
Go
package spotify import ( "context" "fmt" "net/url" "strconv" "strings" ) // Seeds contains IDs of artists, genres and/or tracks // to be used as seeds for recommendations type Seeds struct { Artists []ID Tracks []ID Genres []string } // count returns the total number of seeds contained in s. func (s Seeds)...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
recommendation_test.go
Go
package spotify import ( "context" "net/url" "testing" ) func TestGetRecommendations(t *testing.T) { // test data corresponding to Spotify Console web API sample client, server := testClientFile(200, "test_data/recommendations.txt") defer server.Close() seeds := Seeds{ Artists: []ID{"4NHQUGzhtTLFvgF5SZesLK"...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
request_options.go
Go
package spotify import ( "net/url" "strconv" "strings" ) type RequestOption func(*requestOptions) type requestOptions struct { urlParams url.Values } // Limit sets the number of entries that a request should return. func Limit(amount int) RequestOption { return func(o *requestOptions) { o.urlParams.Set("limi...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
request_options_test.go
Go
package spotify import ( "testing" ) func TestOptions(t *testing.T) { t.Parallel() resultSet := processOptions( After("example_id"), Country(CountryUnitedKingdom), Limit(13), Locale("en_GB"), Market(CountryArgentina), Offset(1), Timerange("long"), Timestamp("2000-11-02T13:37:00"), ) expected :=...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
search.go
Go
package spotify import ( "context" "strings" ) const ( // MarketFromToken can be used in place of the Options.Country parameter // if the Client has a valid access token. In this case, the // results will be limited to content that is playable in the // country associated with the user's account. The user mus...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
search_test.go
Go
package spotify import ( "context" "net/http" "testing" ) func TestSearchArtist(t *testing.T) { client, server := testClientFile(http.StatusOK, "test_data/search_artist.txt") defer server.Close() result, err := client.Search(context.Background(), "tania bowra", SearchTypeArtist) if err != nil { t.Error(err)...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
show.go
Go
package spotify import ( "context" "net/http" "strconv" "strings" "time" ) type SavedShow struct { // The date and time the show was saved, represented as an ISO 8601 UTC // timestamp with a zero offset (YYYY-MM-DDTHH:MM:SSZ). You can use // [TimestampLayout] to convert this to a [time.Time]. AddedAt string...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
show_test.go
Go
package spotify import ( "bytes" "context" "net/http" "testing" ) func TestGetShow(t *testing.T) { c, s := testClientFile(http.StatusOK, "test_data/get_show.txt") defer s.Close() r, err := c.GetShow(context.Background(), "1234") if err != nil { t.Fatal(err) } if r.SimpleShow.Name != "Uncommon Core" { t...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
spotify.go
Go
// Package spotify provides utilities for interfacing // with Spotify's Web API. package spotify import ( "bytes" "context" "encoding/json" "errors" "fmt" "io" "net/http" "strconv" "time" "golang.org/x/oauth2" ) const ( // DateLayout can be used with time.Parse to create time.Time values // from Spotify ...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
spotify_test.go
Go
package spotify import ( "context" "errors" "io" "net/http" "net/http/httptest" "os" "strconv" "strings" "testing" "time" "golang.org/x/oauth2" ) func testClient(code int, body io.Reader, validators ...func(*http.Request)) (*Client, *httptest.Server) { server := httptest.NewServer(http.HandlerFunc(func(w...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
track.go
Go
package spotify import ( "context" "errors" "fmt" "strings" "time" ) type TrackExternalIDs struct { ISRC string `json:"isrc"` EAN string `json:"ean"` UPC string `json:"upc"` } // SimpleTrack contains basic info about a track. type SimpleTrack struct { Album SimpleAlbum `json:"album"` Artists []Simpl...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
track_attributes.go
Go
package spotify // TrackAttributes contains various tuneable parameters that can be used for recommendations. // For each of the tuneable track attributes, target, min and max values may be provided. // // Target: // // Tracks with the attribute values nearest to the target values will be preferred. // For example, yo...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
track_test.go
Go
package spotify import ( "context" "net/http" "testing" ) func TestFindTrack(t *testing.T) { client, server := testClientFile(http.StatusOK, "test_data/find_track.txt") defer server.Close() track, err := client.GetTrack(context.Background(), "1zHlj4dQ8ZAtrayhuDDmkY") if err != nil { t.Error(err) return }...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
user.go
Go
package spotify import ( "context" "errors" "fmt" "net/http" "net/url" "strings" ) // User contains the basic, publicly available information about a Spotify user. type User struct { // The name displayed on the user's profile. // Note: Spotify currently fails to populate // this field when querying for a pl...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
user_test.go
Go
package spotify import ( "context" "fmt" "io" "net/http" "net/http/httptest" "strings" "testing" ) const userResponse = ` { "display_name" : "Ronald Pompa", "external_urls" : { "spotify" : "https://open.spotify.com/user/wizzler" }, "followers" : { "href" : null, "total" : 3829 }...
zmb3/spotify
1,553
A Go wrapper for the Spotify Web API
Go
zmb3
Zac Bergquist
gravitational
app/build.gradle
Gradle
apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "20.0.0" defaultConfig { applicationId "com.zmb.sunshine" minSdkVersion 21 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { ...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/androidTest/java/com/zmb/sunshine/ApplicationTest.java
Java
package com.zmb.sunshine; import android.app.Application; import android.test.ApplicationTestCase; /** * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> */ public class ApplicationTest extends ApplicationTestCase<Application> { public ApplicationTest() { super(...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/androidTest/java/com/zmb/sunshine/data/db/test/DbTest.java
Java
package com.zmb.sunshine.data.db.test; import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.test.AndroidTestCase; import com.zmb.sunshine.data.db.WeatherContract.LocationEntry; import com.zmb.sunshine.data.db.WeatherContract.WeatherEntry; ...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/androidTest/java/com/zmb/sunshine/data/db/test/ProviderTest.java
Java
package com.zmb.sunshine.data.db.test; import android.content.ContentUris; import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; import android.test.AndroidTestCase; import com.zmb.sunshine.data.db.WeatherContract.LocationEntry; import com.zmb.sunshine.data.db.WeatherContract.W...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/DetailActivity.java
Java
package com.zmb.sunshine; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; /** * An activity for displaying a detailed forecast for a particular day. * This activity is only used in the phone (single pane) UI. * In the tab...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/DetailFragment.java
Java
package com.zmb.sunshine; import android.app.Fragment; import android.app.LoaderManager; import android.content.CursorLoader; import android.content.Loader; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.vie...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/ForecastAdapter.java
Java
package com.zmb.sunshine; import android.content.Context; import android.database.Cursor; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CursorAdapter; import android.widget.ImageView; import android.widget.TextView; import com.zmb.sunshine.data.db.W...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/ForecastFragment.java
Java
package com.zmb.sunshine; import android.app.Fragment; import android.app.LoaderManager; import android.content.CursorLoader; import android.content.Intent; import android.content.Loader; import android.content.SharedPreferences; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import ...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/MainActivity.java
Java
package com.zmb.sunshine; import android.app.Activity; import android.app.FragmentManager; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import com.zmb.sunshine.sync.SunshineSyncAdapter; public class MainActivity extends Activity implements ForecastF...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/SettingsActivity.java
Java
package com.zmb.sunshine; import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.view.MenuItem; public class SettingsActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceSt...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/SettingsFragment.java
Java
package com.zmb.sunshine; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import com.zmb.sunshine.data.db.WeatherContract; import com.zmb.sunshine.sync.SunshineSyncAdapt...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/Sunshine.java
Java
package com.zmb.sunshine; import android.content.Context; import android.preference.PreferenceManager; import com.zmb.sunshine.data.Convert; import com.zmb.sunshine.data.db.WeatherContract; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; imp...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/data/AWeatherDataParser.java
Java
package com.zmb.sunshine.data; import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.net.Uri; import com.zmb.sunshine.data.db.WeatherContract; public abstract class AWeatherDataP...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/data/Convert.java
Java
package com.zmb.sunshine.data; /** * Contains various conversions. */ public class Convert { private Convert() { } /** * Convert a temperature in celsius to degrees fahrenheit. * @param celsius * @return */ public static double toFahrenheit(double celsius) { return celsius * ...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/data/DayForecast.java
Java
package com.zmb.sunshine.data; import java.util.Date; /** * An object to represent a single day in the weekly forecast. * All units are metric. */ public class DayForecast { private final double mHighTemperature; private final double mLowTemperature; private final DayOfWeek mDay; private final Str...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/data/DayOfWeek.java
Java
package com.zmb.sunshine.data; /** * A day of the week, such as 'Tuesday'. */ public enum DayOfWeek { MONDAY(1), TUESDAY(2), WEDNESDAY(3), THURSDAY(4), FRIDAY(5), SATURDAY(6), SUNDAY(7); final int mValue; private DayOfWeek(int value) { mValue = value; } /** ...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/data/IWeatherDataParser.java
Java
package com.zmb.sunshine.data; import android.content.Context; import java.net.MalformedURLException; import java.net.URL; /** * Parses weather data returned by a web service. */ public interface IWeatherDataParser { /** * Builds the URL to query for weather data. * * @param locationSetting the...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational
app/src/main/java/com/zmb/sunshine/data/WeatherParseException.java
Java
package com.zmb.sunshine.data; import java.io.IOException; /** * This exception indicates that the weather data returned * by a web service couldn't be parsed. */ public class WeatherParseException extends IOException { private final String mData; private final Exception mInnerException; public Weath...
zmb3/sunshine
1
Sample weather app for Android
Java
zmb3
Zac Bergquist
gravitational