teleren/devto huggingface dataset:
Androidでアプリの定数をBuildConfigではなくYamlから自動生成したい - Gradle Config Plugin
Tags: android, gradle
Published: 2017-11-27 16:16:07

---
title: Androidでアプリの定数をBuildConfigではなくYamlから自動生成したい - Gradle Config Plugin
published: true
description: 
tags: #Android #gradle
---

## 経緯
### やりたかったこと
* アプリケーションで使う定数的な値を一括管理したい
* ProductFlavorごとにAPIの向き先など設定情報を変えたい
* それらを管理するためのクラスを自分で作りたくない

### BuildConfigを使わない理由
* build.gradleが肥大化する
* 定数の記述が多少面倒
	* いちいち型を記述しないといけないので面倒
	* すべての値を文字列で埋め込むのも好みでない

## Gradle Config Plugin
https://github.com/tmiyamon/gradle-config

## 特徴
* ProductFlavorごとにYamlを定義できる
* Yamlから値に参照するためのクラスが自動生成される
	* 値の型はYamlの記述内容に合わせて自動的に解決してくれる

## 導入
### buildscriptにプラグインを追加
```
buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.com.tmiyamon:gradle-config:0.2.1"
  }
}
```

### プラグインを適用する
アプリのプロジェクトがあるbuild.gradleに以下を追記
(app/build.config)

`apply plugin: 'com.tmiyamon.config'`

## 使い方
### コンフィグファイルを作る
アプリのプロジェクトルートに`config`ディレクトリを追加する

ファイル名は以下が対応している

```
config/default.yml
config/default_secret.yml
config/${productFlavor}.yml
config/${productFlavor}_secret.yml
config/${buildType}.yml
config/${buildType}_secret.yml
```

ProductFlavorに応じてこれらのファイルが適宜読み込まれて1つのクラスが生成される

`*_seciet.yml`のファイルは秘匿情報を入れることができる。使う場合はバージョン管理下に置かないように`.gitignore`に入れておくこと

### Yamlに項目を埋めていく
あとはYamlを作っていくだけ

```
size: 2
server: google.com
section:
  size: 3
  servers: [ {name: yahoo.com}, {name: amazon.com} ]
```

このように記述するとビルド時に**Settings**という名前のクラスが生成される

生成されたクラスはこのように値を参照できるようになっている

```
Settings.size   // => 2
Settings.server // => google.com
Settings.section.size // => 3
Settings.section.servers.get(0).name // => yahoo.com
Settings.section.servers.get(1).name // => amazon.com
```

便利！！！😃

## 応用
### kotlinの拡張を使って定数と引数を組み合わせた文字列を作る
例えばベースのURLだけYamlに書いておいて、パスの組み合わせをkotlinの拡張で実現する

```
url:
  base: https://hoge.com
```

続いてkotlin側でプロパティを拡張する
```
fun Settings.Url.getDetail(id: String) = "$base/detail/$id"
```

こんな感じでアプリ上で参照できるようになる
```
Settings.url.getDetail("1") // => https://hoge.com/detail/1
```

## あとがき
設定情報は何かと細かく組み合わせたり、たくさん記述したりする部分なので、管理しやすくしたい

このプラグインはそうした部分の要求を叶えてくれるよいアプローチに思えた
Что обеспечивает interface и для чего он нужен
Tags: php, webdev, interface
Published: 2018-02-03 14:34:12

---
title: "Что обеспечивает interface и для чего он нужен"
published: true
tags:  php, webdev, interface
canonical_url: http://phpprofi.ru/blogs/post/80
---

Создание и внедрение интерфейсов в наш код - это важно. Это помогает с подменой компонентов, облегчает тестирование, отделяет "что" от "как".

Но просто влепить интерфейс к классу и забыть - этого не достаточно.

Мы также должны подумать о том, на что мы "натянем" этот интерфейс.

![](http://phpprofi.ru//resources/img/blogs/a9479b26-9e9b-4d79-9075-6fea22e01780.jpeg)

----
Читать далее: http://phpprofi.ru/blogs/post/80

----
En: https://robertbasic.com/blog/what-implements-an-interface/
Best technology-related, non-fiction books
Tags: books, discuss
Published: 2017-11-27 14:15:33

---
title: Best technology-related, non-fiction books
published: true
description: 
tags: books, discuss
cover_image: https://thepracticaldev.s3.amazonaws.com/i/uw8y21jxarjkjo8gmg99.png
---

It appears that most developers [really like reading books](https://dev.to/ben/books-appear-to-still-be-popular-in-software-development-d85), but this is a specific ask.

### What are the best, technology-related, non-fiction books you've ever read?

To get things started, here's my **Top 5**:

- **The Soul of A New Machine** by Tracy Kidder
- **Where Wizards Stay Up Late: The Origins of the Internet** by Katie Hafner and Matthew Lyon
- **The Cuckoo's Egg** by Cliff Stoll
- **Show Stopper! The Breakneck Race to Create Windows NT and the Next Generation at Microsoft** by G. Pascal Zachary
- **Masters Of Doom: How two guys created an empire and transformed pop culture** by David Kushner

### What are your favourites?
Summary of pointer of Golang
Tags: go
Published: 2017-11-27 13:56:08

---
title: Summary of pointer of Golang
published: true
description: 
tags: Golang
---

Sometimes I confuse how to retrieve from pointer variable. So I wanna summary the pointer of Golang not to forget them.
Because I haven't used languages which have pointer variable. 

Then it's just memo for me.

- & stands for the memory address of value.
- * (in front of values) stands for the pointer's underlying value
- * (in front of types name) stands for to store an address of another variable

It's an example

```go
package main

import "fmt"

type H struct {
	id *int
}

func main() {
	a := 10
	
	p := &a
	fmt.Println(p)	//0x10410020
	fmt.Println(*p)	//10
	
	a = 11
	fmt.Println(p)	//0x10410020
	fmt.Println(*p)
	
	q := 90
	b := H{id: &q}
	fmt.Println(b.id)	//0x1041002c
	fmt.Println(*b.id)	//90
	
	q = 80
	fmt.Println(b.id)	//0x1041002c
	fmt.Println(*b.id)	//80
}
```
Adding Proxy-Authorization header in swagger
Tags: discuss, swagger, swashbuckle
Published: 2017-11-27 11:55:29

---
title: Adding Proxy-Authorization header in swagger
published: true
description: 
tags: #discuss #swagger #swashbuckle
---

Hi all,
I already posted this question on [stack overflow](https://stackoverflow.com/questions/47509258/add-proxy-authorization-header-in-swagger), but I think, that here I can find interested people faster.

I need to add specific header on swagger ui using .net core. Is there any way to include header like this?

Already tried:
* implementing IOperationFilter:
```c#
public void Apply(Operation operation, OperationFilterContext context)
{
    if (operation.Parameters == null)
        operation.Parameters = new List<IParameter>();

    if (operation.Parameters.All(p => p.Name != "Proxy-Authorization"))
    {
        operation.Parameters.Add(new NonBodyParameter
        {
            Name = "Proxy-Authorization",
            In = "header",
            Description = "Proxy-Authorization token",
            Required = true,
            Type = "string"
        });
    }
}
```

* adding security definition:

```c#
options.AddSecurityDefinition("Authorization", new ApiKeyScheme()
{
    In = "header",
    Description = "Please insert Proxy Authorization Secret into field",
    Name = "Proxy-Authorization",
    Type = "apiKey"
});
```

Both didn't work. When I change header name everything works fine (`HttpContext.Request.Headers` contains desirable header), but this specific ( `Proxy-Authorization`) header is wiped out from a call.

Did you ever meet this issue? How to solve it?

EDIT:

I confirmed that this is not the issue in .net core only. Full .net framework has also this bug.

Furthermore it is only affected on header with `proxy-` prefix.
Seven Deadly Wastes: Don’t Over Think It
Tags: agile, productivity, softwaredevelopment
Published: 2017-11-28 16:42:28

---
title: "Seven Deadly Wastes: Don’t Over Think It"
published: true
tags: agile,productivity,software-development
canonical_url: https://medium.com/going-faster/seven-deadly-wastes-dont-over-think-it-e2d56d747096
---

#### Going Faster: Issue&nbsp;15

![](https://cdn-images-1.medium.com/max/1024/1*1rXVXiSbVNSKjmq3u_FRkA.jpeg)

_The Seven Wastes are an idea from_ [_lean manufacturing_](https://en.wikipedia.org/wiki/Muda_(Japanese_term)#Seven_wastes)_, and I’m exploring how they relate to software development. Last time was_ [_waiting_](https://dev.to/jezhalford/seven-deadly-wastes-waiting-5fn)_, and this week is_ **_over processing_** _._

Over processing can be summarised as working too hard. If you’ve ever built in a caching layer “just in case”, if you’ve ever implemented an entirely image processing library just to churn out a few thumbnails, if you’ve ever spent days drawing diagrams and agonising over the problem, then maybe you’re over processing.

It’s the kind of thing engineers love to do. It’s gold plating, it’s making it _nice._ But nice isn’t always what the customer wants, and it isn’t always what solves the&nbsp;problem.

I’m a big fan of building software in lots of small steps. Build the smallest thing, ship it, and improve it. This approach is great because it keeps you grounded to the users’ needs, and it also helps you avoid wasting time on over processing. It maintains focus.

So, stop thinking about it, stop polishing it, just ship&nbsp;it.

_Going Faster: Weekly ideas on speeding up your software team by Jez Halford, a software development consultant helping teams to deliver better software more&nbsp;quickly._

_There’s more from Jez on_ [_Twitter_](https://twitter.com/jezhalford)_,_ [_Medium_](https://medium.com/@jezhalford)_and_ [_jezhalford.com_](https://jezhalford.com/)

* * *
Why there is so much hype around doing things in JavaScript?
Tags: discuss
Published: 2017-11-27 08:29:34

---
title: Why there is so much hype around doing things in JavaScript?
published: true
tags: discuss
---


Can someone tell me why people are so much hyped about javaScript libraries, SPA's, throwing more javaScript to browsers, using excessive tooling and all that. This seems a lot of questions but all that says one thing why people are making front-end complicated?

At the end of the day, javaScript has its own [flaws](https://www.youtube.com/watch?v=2pL28CcEijU) and that can't be changed because of backward compatibility. 

shouldn't we ignore writing JavaScript. Instead of throwing everything to JavaScript thinking that it will make things better.
Which Programming Language To Learn?
Tags: discuss
Published: 2017-11-27 06:34:31

---
title: Which Programming Language To Learn?
published: true
description: I want to learn strong typed and low level programming language but which one?
tags: discuss
---

Hello everyone,

I'm fullstack web developer. I know php, javascript, nodejs and learned a little go lang. I want to improve myself and learn strong typed, low level programming language but I don't know which one.

I want to learn new language because I want to learn new ways of thinking about problems and new ways of solving problems. I want to improve myself at programming. I can't feel like I'm programming or solving problems at web development anymore. I'm just doing same things at web development.

C/C++ is good option but it has lots of keyword (over 90 if I remember correctly) and it's old.

Rust is good option too. New and modern language, Mozilla develops it (I love Mozilla) and it's really favorite language at stackoverflow but it's new and doesn't have much library bla bla.

Python is good option. It has lot's of library, very well supported...

What would you do and why?
Implement your GraphQL server on Firebase Function
Tags: firebase
Published: 2017-11-27 02:44:19

---
title: Implement your GraphQL server on Firebase Function
published: true
description: 
tags: firebase
---


## Why

SPA and Mobile App need just one single endpoint to graphql.

This way can not implement subscription with ws backend. I think I don't need it because firestore will resolve it.

## What I will not write in this article...

- How to deploy to firebase
- GraphQL Server implementation
- webpack / npm install / package.json

## functions code

functions/index.js

```js
const functions = require('firebase-functions')
const express = require('express')
const { graphqlExpress } = require('apollo-server-express')
const bodyParser = require('body-parser')
const { makeExecutableSchema } = require('graphql-tools')

const schema = makeExecutableSchema({
  typeDefs: [/* Your schema.graphql */],
  resolvers: {/* Your resolver */}
})

const server = express().use(
  bodyParser.json(),
  graphqlExpress({ schema, context: {} })
)

exports.graphql = functions.https.onRequest(server)
```

## Send request to graphql

At first you need `firebase deploy`

Write your firebase.rules to proxy graphql endpoint

```json
{
  "functions": {
    "source": "functions"
  },
  "hosting": {
    "rewrites": [
      {
        "source": "/api/graphql",
        "function": "graphql"
      }
    ]
  }
}
```

Run `firebase serve` on your lacal and request query by apollo client.

```js
import 'isomorphic-fetch'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import gql from 'graphql-tag'

const client = new ApolloClient({
  link: new HttpLink({ uri: 'http://localhost:5000/api/graphql' }),
  cache: new InMemoryCache()
})

client.query({
  query: gql`<your query>`
}).then(ret => {
 console.log(ret)
})

```

CAUTION:2017/11/27 I have a problem about apollo-link so I add work arround to node_modules directly. https://github.com/apollographql/apollo-link/issues/248
Explain Service Workers Like I'm 5
Tags: explainlikeimfive, discuss
Published: 2017-11-27 02:27:06

---
title: Explain Service Workers Like I'm 5 
published: true
description: I want to get a sweet offline page like the ones popping up all over the web.
tags: explainlikeimfive, discuss
---

Not understanding how to use a service worker to get a PWA and offline page up and running.
Books appear to still be popular in software development
Tags: books
Published: 2017-11-26 18:57:19

---
title: Books appear to still be popular in software development
published: true
description: From what I've observed, software developers are still very much into books.
tags: books
cover_image: https://thepracticaldev.s3.amazonaws.com/i/x5thz28kj80h1ayf535n.jpg
---

Whenever the subject of software development books come up, a group folks jump in to talk about their absolute favorite books, and a lot of people hop in to talk about how books are no longer useful. They talk about how quickly they become out of date, or how they've become passé.

{% link https://dev.to/lpasqualis/11-books-all-software-engineers-must-read %}

But from what I've observed, software developers are still very much into books. Book-related posts on [dev.to](/) _always_ attract a lot of reads. When people post about books they want to recommend, _so many developers_ click through to read.

{% link https://dev.to/ben/what-are-your-must-read-programming-books %}

When people _talk_ about books, it's hard to know what inferences to make. People probably lie about how much they read because the ability to get through books is a positive trait or habit, like getting to the gym. Some might also follow along with the crowd in expressing how books are no longer relevant. So I can't say I'd really trust what people are saying, but I trust my observations that people click through and read posts about books at a great rate.

Click-through doesn't measure a whole lot, but it certainly implies an interest in the subject. Tweets from [@ThePracticalDev](https://twitter.com/thepracticaldev) about books get up to 7.5% click through, higher than just about any other posts, and they always perform above average. Clicking a link is also a private action. If someone clicks through to read something, they aren't sending social signals or being judged. Presumably this process is unadulterated by social pressures the way a public comments might be.

I would assume that physical books are steadily losing popularity in favor of e-books, but long-form writing in this space still attracts great interest. I've personally found the last couple software books I've finished to be of tremendous value, for what it's worth.
How to apply for a master degree?
Tags: discuss, master, university
Published: 2017-11-26 18:56:10

---
title: How to apply for a master degree?
published: true
description: 
tags: discuss, master, University
---

Hello everyone! I've been planning on going to Canada or US for a master degree in computer science or computer engineering. I'm from Brazil and here we have our own way to get enrolled into universities. Since most of them belongs to the government, we have to pass some tests in order to enroll to the university.

In Brazil, public universities are free of tuition, and I know that in Canada and US they are very expensive.

Is there some way to get a fully founded scholarship for a master degree in those countries?
How to Add Author Bio to Posts in Jekyll
Tags: jekyll, python
Published: 2017-11-26 16:49:29

---
title: How to Add Author Bio to Posts in Jekyll
description: A guide to including biographical information for authors in Jekyll blog posts
published: true
permalink: adding-author-bios-in-jekyll
tags: Jekyll, Python
---

My blog [Datalogues](https://datalogues.com) is powered by [Jekyll](https://jekyllrb.com/), a static-site generator. The theme I selected for the site did not support authors out of the box however it is easy to implement author functionality in Jekyll.

### 1) Edit/create appropriate folders and files in Jekyll project

- front matter of individual blog posts where author should be included
- \_layouts/post.html


and created the following folders/files:
- \_data/authors.yml
- \_includes/author_bio.html



### 2) Store Author Data
I have stored my author data in a folder called `_data` that contains a file `authors.yml`. The author information associated with `monica_powell` is pulled into my post from the `authors.yml` data file.

```
monica_powell:
    name: Monica Powell
    email: monica@aboutmonica.com
    twitter: http://twitter.com/waterproofheart
    bio: Monica Powell is a web technologist that cares about increasing the visiblity of underestimated individuals in technology. In 2015, she received the &#35;GIRLBOSS award from Sophia Amoruso’s Girl Boss Foundation. She’s currently focusing on making tech more enjoyable & accessible and is always up to chat data visualizations, web development or &#35;BlackGirlMagic.
    image: http://www.datalogues.com/assets/images/monica-powell-headshot.jpg
```

### 3) Reference relevant authors in the front matter of individual blog posts
In the front matter of each blog post in Jekyll you should reference authors in [YAML (YAML Ain't Markup Language)](http://www.yaml.org/start.html) using the following format `author: NAME OF AUTHOR`. The name of author should be an exact match one of the variables in your `authors.yml`

The front matter in Jekyll sets the metadata for a post and is key to properly building posts. YAML is a human friendly data serialization standard for all programming languages.

Here is an example of the front matter for this particular post.
```
layout: post
title: How to Add Author Bio in Jekyll
description: A guide to adding author bios in Jekyll
image: assets/images/author-bio.png
permalink: adding-author-bios-in-jekyll
author: monica_powell
comments: true
```

### 4) Define HTML for author bio

in the folder `_includes` create a file called `author_bio.html` to define the HTML for how author bio's should be displayed


{% gist https://gist.github.com/M0nica/11c8db6f267e94845f96c1afcf170769 %}


### 5) Add author bios to the post layout

Add a line in `post.html` where author bio should appear and pull in the HTML as defined above in `author_bio.html`. The logic is set so that it will only call that HTML template if there is author information associated with this particular post.

```
  ## if there is an author bio
  {% if author.bio %}
      {% include author_bio.html %}
  {% endif %}
```
What technology is used to make dev.to so fast ?
Tags: webdev, beginners, discuss
Published: 2017-11-26 15:31:56

---
title: What technology is used to make dev.to so fast ?
published: true
description: 
tags: #webdev #beginner, discuss
---
I just crashed in here and found out that this web is super fast, all the posts seems take no time to load.
Dynamically adding CSS to webviews in Swift 
Tags: swift, ios
Published: 2017-11-26 15:25:33

---
title: Dynamically adding CSS to webviews in Swift
published: true
description: Adding CSS to webviews in Swift
tags: Swift, iOS
---
*This article was first published here https://www.ceri-anne.co.uk/dynamically-add-css-to-webviews-in-swift*

This week, I needed to figure out how to dynamically add css to a webView in iOS and it was much easier than I thought it would be.

All you need to do is make use of the webViewdidFinish function in the WKNavigationDelegate and evaluateJavaScript

{% gist https://gist.github.com/c3163d98822b6bc4c3edb16943c684c1 %}

This code will change the background colour of the webpage you are displaying to red.

To show how this works, I created a simple sample app with a series of buttons with colour choices on:

<img class="size-medium wp-image-166 aligncenter" src="http://ceri-anne.co.uk/wp-content/uploads/2017/11/view-169x300.png" alt="" width="169" height="300" />

Clicking on any of the buttons takes you to a webView which displays www.google.co.uk but the background colour of the webpage changes depending on the button chosen. So if you click on green you're taken to this page:

<img class="size-medium wp-image-165 aligncenter" src="http://ceri-anne.co.uk/wp-content/uploads/2017/11/webView-169x300.png" alt="" width="169" height="300" />

To do this, in the ViewController I added an IBAction which performs the segue when a button is tapped. The button text is then passed through to the WebViewController:

{% gist https://gist.github.com/83db251c9b6a7dc5423bdb854615932d %}

In the WebViewController there is a function getHexColour which determines the hex code colour based on the colour set in the segue.

Then in webViewDidFinish I created the css and JavaScript and applied that to the webView using the evaluateJavascript function:

{% gist https://gist.github.com/3b8f9216664dc6b51f67229dc0266e7c %}

Here's a link to the sample project code: <a href="https://github.com/Ceri-anne/WebViewCss">https://github.com/Ceri-anne/WebViewCss</a>

&nbsp;
How to build firebase function by webpack
Tags: firebase
Published: 2017-11-26 12:27:59

---
title: How to build firebase function by webpack
published: true
description: 
tags: firebase
---

## Why

Cloud Function for Firebase has node v6.11.x. It's too old for node.js developer and anyway we need our own build stack. For example, I'm babel and flow user.

In addition, in isomorphic environment like SSR, packages are expected same version. So I think bundling all source into one script is most easy solution to publish.


## How to build

My project dirs.

```
package.json
firebase.json
functions/
  _dist/ # generated by webpack
    index.js
    package.json
  index.js # entry point
  webpack.config.js
```


```js
// functions/webpack.config.js
const pkg = require('../package')
const GenerateJsonPlugin = require('generate-json-webpack-plugin')

// Set externals that you don't want to build by webpack
const externals = [
  'firebase-admin',
  'firebase-functions'
]

const genPackage = () => ({
  name: 'functions',
  private: true,
  main: 'index.js',
  license: 'MIT',
  dependencies: externals.reduce(
    (acc, name) =>
      Object.assign({}, acc, {
        [name]:
          pkg.dependencies[name] ||
          pkg.devDependencies[name]
      }),
    {}
  )
})

module.exports = {
  entry: [__dirname + '/index.js'],
  output: {
    path: __dirname + '/_dist',
    filename: 'index.js',
    libraryTarget: 'commonjs'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: 'babel-loader',
        exclude: /node_modules/
      }
    ]
  },
  externals: externals.reduce(
    (acc, name) => Object.assign({}, acc, { [name]: true }),
    {}
  ),
  plugins: [new GenerateJsonPlugin('package.json', genPackage())]
}
```

This webpack build `functions/_dist/*`.


Write your firebase.json

```
{
  "functions": {
    "source": "functions/_dist"
  },
  "hosting": {
    "rewrites": [
      {
        "source": "/api/hello",
        "function": "hello"
      }
    ]
  }
}

```


Let's build and deploy.

```
$ npm i -g firebase-tools webpack
$ webpack --config functions/webpack.config.js
$ cd functions/_dist/; npm install
$ firebase deploy only functions
```

You can add this task as npm scripts.