teleren/devto huggingface dataset:
Why are those web services sending "Number" with double-quotes in JSON?  Castable library can handle them.
Tags: typescript, javascript
Published: 2017-12-21 10:23:25

---
title: Why are those web services sending "Number" with double-quotes in JSON?  Castable library can handle them.
published: true
description: Castable library sanitizes dirty external data by casting all properties at run time to the types specified at compile time.
tags: TypeScript, JavaScript
---


# Castable TypeScript Library
[Castable](https://github.com/bitrinjani/castable) sanitizes dirty external data by casting all properties at runtime to the types specified at compile time.

# Why do you need this library?
A lot of web services return `number` type fields **with double-quotes** in JSON. If you convert them by JSON.stringify, the double-quoted numbers will become `string` type!!

```JavaScript
const serverResponse = `{
　　"name": "Milk", 
　　"price": "200", 
　　"tax": "10", 
}`;
const product = JSON.parse(serverResponse);
const sum = product.price + product.tax;
console.log(`sum: ${sum}`); // "200" + "10" = "20010"⛔️
```

TypeScript type annotation can help it? No, TypeScript cannot check such runtime type mismatch. You will get the same result even type annotation is perfect.

That's why I've made this library. Castable can convert those types at runtime. All fields will be converted to the annotated types.

```TypeScript
import { cast, Castable } from 'castable';

class Product extends Castable { 
  @cast name: string;
  @cast price: number;
  @cast tax: number;
}

const serverResponse = `{"name": "Milk", "price": "200", "tax": "10"}`;
const product = new Product(JSON.parse(serverResponse));
const sum = product.price + product.tax;
console.log(`sum: ${sum}`); // 200 + 10 = 210👍
```

Castable internally applies Number("200") for price field and Number("10") for tax field in order to cast them to the correct type, recognizing those are actually `number` type, not `string`.

Supported types:
- number: "100" will be converted to real number `100`.
- boolean: string "true", "false" in JSON will be real boolean `true`, `false`.
- Date: Any string representation supported by Date constructor, like "Thu Dec 21 2017 18:38:58 GMT+0900 (Tokyo Standard Time)"
- Nested type
- Array<T>
- Multi-dementional Array<T> 

# Install

```bash
npm install @bitr/castable
```

# Usage
1. Extend Castable
2. Add `@cast` decorator to primitive type field (string, number, boolean)
3. Add `@cast(Date)` decorator to Date type field
4. Add `@cast @element(T)` to Array<T> type field
4. Add `@cast` decorator to nested type
5. Do same to all nested types

# Example
This library is extensively used in [R2](https://github.com/bitrinjani/r2), e.g. [type.ts](https://github.com/bitrinjani/r2/blob/master/src/Quoine/types.ts).
Hide or Remove Add to Cart Button In WooCommerce Store
Tags: addtocartbutton
Published: 2017-12-21 09:58:42

---
title: Hide or Remove Add to Cart Button In WooCommerce Store
published: true
description: Now you can easily hide or disable add to cart button in WooCommerce store.
tags: add to cart button 
---
<img src="https://www.wpblog.com/wp-content/uploads/2017/09/add-to-cart.jpg">

This Post was originally published on WPblog <a href="https://www.wpblog.com/add-to-cart-button-in-woocommerce-store/">Hide or Remove Add To Cart Button In WooCommerce Store</a>.

I have seen that most of the store owners got confused while removing or disable the add to cart button. Now for any shop page or product you can remove the the add 2 cart button. You just have to follow these simple steps. In woocommerce.php (located wp-content/plugins/woocommerce)


`
function WpBlog() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart');
return WooCommerce::instance();
}
`

After that refresh shop page and you will see that the button will be removed from the page. 

You can also remove add to cart button for specific product pages.

Add this code to the functions.php (located in the theme folder): 

`
add_filter('woocommerce_is_purchasable', 'wpblog_specific_product');
function wpblog_specific_product($purchaseable_product_wpblog, $product) {
return ($product->id == specific_product_id (512) ? false : $purchaseable_product_wpblog);
}
`
How to get innodb_lock_wait_timeout with Ruby on Rails
Tags: rails, mysql
Published: 2017-12-21 02:46:14

---
title: How to get innodb_lock_wait_timeout with Ruby on Rails
published: true
description: Ruby on Rails
tags: Ruby on Rails, MySQL
---

[Session]
`ActiveRecord::Base.connection.select_all(“SELECT @@SESSION.innodb_lock_wait_timeout”).to_hash`

[Global]
`ActiveRecord::Base.connection.select_all(“SELECT @@GLOBAL.innodb_lock_wait_timeout”).to_hash
`
What developer podcasts do you listen to or watch?
Tags: discuss, podcast
Published: 2017-12-20 22:47:26

---
title: What developer podcasts do you listen to or watch?
published: true
description: 
tags: discuss, podcasts
---


I've never really gotten into podcasts, but I feel like now is the time.

I'd really love to hear your recommendations for podcasts that you listen to or watch. I mainly program in JavaScript or Ruby, so things in that space are good, but I'm interested in general too.

Thanks!
I'm a co-founder of dev.to, ask me anything!
Tags: ama
Published: 2017-12-20 18:48:53

---
title: I'm a co-founder of dev.to, ask me anything!
published: true
description: Ask me anything about dev.to or my past experience. 
tags: ama
cover_image: https://thepracticaldev.s3.amazonaws.com/i/k3brznsttuucqa033z5z.jpg
---

Hey! I'm Peter and I've been working on dev.to with Ben & Jess since last January. Here's some more info about me:

- I work on the "business" side (strategy, operations, etc.)
- I'm the _least technical_ member of our team
- I was one of Tinder's very first users
- I sold an online community in 2011
- I'm half-Korean, half-Ashkenazi
- I was once on the Montel show
- I was an english major
- I love playing sports

Feel free to ask me anything!
Do you apply testing in your side projects?
Tags: discuss, testing, tdd
Published: 2017-12-20 18:09:53

---
title: Do you apply testing in your side projects?
published: true
tags: discuss, testing, tdd
---

Hi everyone 👋
Yesterday I started to learn more about [TTD](https://en.wikipedia.org/wiki/Test-driven_development) (test-driven-development) in JS. I checked out [Mocha](https://mochajs.org), [supertest](https://www.npmjs.com/package/supertest) & [assertthat](https://www.npmjs.com/package/assertthat) and everything was very easy set up. I wrote some simple test cases (unit + integration) in Node.js, so overall it looked like a very nice strategy to increase the quality of the product/code (overtime). But then I asked myself, why I have never done this before? What kept me back? I always thought, that if you are the only developer of your side project it wouldn't make sense to write those tests because you would lose a lot of time instead of just trying out your idea.
That's why I would like to ask you: 
* **Do you apply testing in your side projects?**
* **Does it make sense to you?**
* **Have you benefit from that, what is your experience?** 
* **Do go more for unit tests or more for integration tests?**
* **Do you test your REST API in this way or just hit the API by Postman as I do? 😅**

Maybe you have some advice for me, let's discuss!

Already, thanks in advance!
Best, Nicho ✌️
Some Career Advice
Tags: career, node, discuss
Published: 2017-12-20 16:14:40

---
title: Some Career Advice
published: true
description: 
tags: career, node.js, discuss
---
Hello everyone. I had sort of a personal query.

I've worked for two years in a support project where I learned almost nothing. But after a year in that project, I started learning Node.JS and Angular all by myself. I've been learning and trying hard to get expertise in MEAN stack ever since.

Now, my current company is offering, kinda forcing me to take up a project in Python, Django, and Ember.JS, their excuse being that I have no relevant coding experience, just a couple POCs, and DIY projects.
The manager of that project told me that technology doesn't matter, but I've been working hard on this stack for a year now, starting from scratch, working 6+ hours every day after office hours.

I just need some advice whether I should take up that project or let it go and wait. I only got a day to decide.

Thanks in advance!
Renamed tools in Ethereum
Tags: ethereum, solidity, blockchain, smartcontract
Published: 2017-12-20 15:26:44

---
title: Renamed tools in Ethereum
published: true
description: 
tags: Ethereum, solidity, blockchain, smartcontract
---

`New name(Old name)`

- [OpenEthereum](https://www.parity.io/ethereum/) (Parity Ethereum)
- [Remix](https://remix.ethereum.org) (Browser-Solidity)
- [solidity-coverage](https://github.com/sc-forks/solidity-coverage) (Solcover)
- [ganache-cli](https://github.com/trufflesuite/ganache-cli) (test-rpc)
- [Vyper](https://github.com/ethereum/vyper)(viper)
- [OpenZeppelin Contracts](https://github.com/OpenZeppelin/openzeppelin-contracts)(OpenZeppelin Solidity, Zeppelin Solidity)
- [OpenZeppelin SDK](https://github.com/OpenZeppelin/openzeppelin-sdk)(ZeppelinOS)
- [OpenZeppelin starter kit](https://github.com/OpenZeppelin/starter-kit)(ZEPKIT)
automation test engineers and OOP
Tags: oop, testing, java
Published: 2017-12-20 14:39:24

---
title: automation test engineers and OOP
published: true
description: 
tags: oop, testing, java
---

My fellow test engineers need to re-read OOP principles and understand their value and really start using them. E.g. they write - 
```java
class Epic {
    Type field = new Type();
}

class Test1 extends Epic {
    @Test
    public void test() {
        assertNotNull(field);
    }
}
```
instead of -
```java
class Epic {
}

class Test1 extends Epic {
    private Type field = new Type();

    @Test
    public void test() {
        assertNotNull(field);
    }
}
```
Their reasoning is: "When we add another test under this epic and declare the same field, we will get a Sonar issue for duplicate fields."

My conclusion is they are still not right. You need to declare and initialise fields only in the class where you use it, not in a superclass hoping that someone some day will use it in another child class.
On State Dependence and Coupling
Tags: javascript, softwaredevelopment
Published: 2018-03-14 12:17:08

---
title: On State Dependence and Coupling
published: true
tags: javascript,software-development
canonical_url: https://medium.com/@hazterisk/on-state-dependence-and-coupling-b644a55f9b1c
---

Any function in your application depending on the state of a mutable object === a bad time.

What is so bad about depending on the state of a mutating object for a function to work correctly every time?

Everything. Here is an abridged list of all of the things.

1. Things will break when something goes wrong in the mutating object. Notice I said when, I’ll get to that, but for now you’re screwed because the dependent function will behave in ways that may or may not be correct. And this is worse than wrong, because things that are sometimes wrong can make it to production. Awesome right? This highlights the problem with non deterministic functions.
2. Not only do you have two objects tightly coupled, but the coupling is implicit. Because the mutable state has no explicit tie to the dependent function, a developer has no way of knowing that any mutations or functional changes to said mutable object might alter the function of the system in seemingly unconnected ways. Congratulations, you planted a land mine. This highlights the importance of single responsibility principle and separation of concerns principle.
3. Something will go wrong because land mines get stepped on when code is iterated upon. This highlights the importance of adhering to principles as justification for why you do things instead of “I had to because [insert contextual and shortsighted reasoning here]”
4. The problem you didn’t solve in the first place will become apparent when the dependent function goes wrong, and solving it now may require serious refactoring. The thing about decisions is that they stack and branch. If you make a bad one early on, then any good decision downstream is compromised. This highlights the importance good planning and design as well as the open closed principle.
5. RACE CONDITIONS! Not only is the function dependent on the state of the mutable object, but it’s also dependent on the timing between when the dependent function is called and when the object is mutated. The best part about this is that you can now make a change in a completely unrelated area of the system and cause this race condition to exhibit. This highlights the impact of state altering control flow and how class cohesion (or lack of it) impacts maintainability.

So how do we avoid this? There are lots of ways, but ultimately every situation is different and good principles are a great guide (just like real life!). Also, look into function purity.

Choosing domain specific heuristics is also a good idea. Things like: tend toward flat structure, prefer long descriptive names over short ambiguous ones, try to push branching logic up the call stack, and anything else that can add a bit of direction to a given situation when you’re not sure what to do. Which for me is most of the time.
What are the best practices for accepting PRs?
Tags: discuss, opensource
Published: 2017-12-20 13:36:10

---
title: What are the best practices for accepting PRs?
published: true
tags: discuss, open source
---

I started contributing to open source about a year ago, and I've started a couple of projects myself so it's kind of weird I'm having this thought now.

I recently started a project and I expect to receive PRs to the `dev` branch. But what are the best practices to ensure that I'm not merging code that doesn't do what it's supposed to do (I don't mean broken code this time cos most can be handled with testing) into the same stream everyone is working on which is `dev`.

Which leads to my question or thought, whats actually the best approach to accepting PRs to a project or how do you currently do it? Because `dev` automatically becomes where everyone's changes end up before any release or something like that.
Управление зависимостями и решение конфликтов в PHP через Composer
Tags: php, webdev, composer
Published: 2018-02-06 13:44:27

---
title: "Управление зависимостями и решение конфликтов в PHP через Composer"
published: true
tags:  php, webdev, composer
canonical_url: http://phpprofi.ru/blogs/post/86
---

Когда вы создаете PHP-приложение или библиотеку, вы, как правило, имеете 3 вида зависимостей:

- Жесткие зависимости: то, что требуется вашему приложению/библиотеке, чтобы работать
- Необязательные зависимости: например, ваша PHP-библиотека может предоставлять адаптеры/бриджи для различных фреймворков
- Зависимости для разработки: инструменты отладки, тестирования...

## Как управлять этими зависимостями?

[![](https://cdn-images-1.medium.com/max/800/1*hQ6fh7VWqkfaPmXR8N4CoQ.png)](http://getcomposer.org/)

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

----
En: https://medium.com/@tfidry/managing-your-dependencies-in-php-321d584441ab
TIL: Match unicode letters in regex
Tags: todayilearned, regex, unicode
Published: 2017-12-20 12:41:51

---
title: "TIL: Match unicode letters in regex"
published: true
description: "How I learned how to match unicode letters in regex while working on an exercise from exercism.io."
tags: todayilearned, regex, unicode
canonical_url: https://sven-dittmer.netlify.com/2017/12/20/match-unicode-letters-in-regex.html
---
Note: This post was originally posted on [sven-dittmer.netlify.com](https://sven-dittmer.netlify.com/2017/12/20/match-unicode-letters-in-regex.html).

Today I faced an interesting challenge on [exercism.io](http://exercism.io).
To me, the most interesting part was about finding out if a sentence was
yelled or not. A sentence counts as yelled if all its word are upper case.

You can find the whole challenge here: [Bob in elixir - exercism.io](http://exercism.io/exercises/elixir/bob/readme)

Here's my first attempt:

```elixir
String.upcase(input) == input
```

This one passes some tests, but it failes for sentences that don't contain any word, like "*1, 2, 3*". Since there's no upper case word, it shouldn't count as yelled.
Next try:

```elixir
input =~ ~r/\w/u && String.upcase(input) == input
```

With this regex, I made sure the word contains at least on letter. And since I'm still checking that every letter is upper case, that should do the job, right? Well, not quite.

The exercise's last test was about a sentence yelled in Russian. (Link:
[Bob in elixir test suite](http://exercism.io/exercises/elixir/bob/test-suite#L81))
Turns out `\w` matches only letters of the latin alphabet. It is equivalent to `[a-zA-Z]`. To make the regex work, I'd have to match any unicode letter. After googling a little bit, I found the solutions here: [Regular-Expressions.info](https://www.regular-expressions.info/unicode.html). With <abbr title="Perl Compatible Regular Expressions">PCRE</abbr> we can match different categories of unicode with `\p{<some_unicode_category>}`. For letters, you can use `\p{Letter}` or its short form `\p{L}`. Here's the final code that makes the last test pass:

```elixir
input =~ ~r/[\p{L}]/u && String.upcase(input) == input
```

This is my first post on dev.to. Feedback is much appreciated!
Biggest library of ready-made API collections for Postman
Tags: producthunt, api, webdev, postman
Published: 2017-12-20 10:26:50

---
title: Biggest library of ready-made API collections for Postman
published: True
description: Ready-made API collections for Postman
tags: Product Hunt, API, Web development, Postman
---

Happy to announce that today [Zeroqode](https://zeroqode.com/) has launched [Postman Collections on Product Hunt](https://www.producthunt.com/posts/postman-collections). These API collections allow you to import ready-made tested APIs in your Postman with one click. We invite you to participate in the discussion and share your opinion :)
What is your opinion on CSS in JS and generating Static sites from JS frameworks?
Tags: discuss
Published: 2017-12-20 10:02:15

---
title: What is your opinion on CSS in JS and generating Static sites from JS frameworks?
published: true
tags: discuss
---

There seems to be a discussion going on about the use of CSS-in-JS and using JavaScript frameworks to generate static sites. One team is convinced that doing anything in JavaScript that you can do with HTML or CSS is grossly over-complicating stuff, the other team loves using all the new tools and feels like their solutions solve great problems.

The Twitter rants I've seen about this subject have yet to be more than people presenting their own opinion as an immutable state (please kill me now), which isn't very informative on the topic. What does shine through is that there seems to be a gap in the domain of front-end development between developers who came in the traditional route, using HTML, CSS and a sprinkle of JavaScript as their base and developers who totally went for learning JavaScript libraries / frameworks and almost see CSS and HTML as the side-thing. 

Confession time: All the talk about frameworks, etc. can seem scary if you haven't really read up on them. At my old job, the back-end developer also handled a few assignments that needed React because I totally wasn't ready for that level of Front-end / JavaScript complexity. I did feel bad about it. I never signed up for using scary JavaScript frameworks, but here it was and it was supposed to be part of my domain. 

Now I'm totally hip with it, but if this discussion was raging as much two years ago, I'd probably have a knee-jerk reaction towards solutions based on JavaScript frameworks.

I'll be writing a full article about this topic soon but right now I'd like web developers to share their opinion on this topic.

What do you think of CSS in JS and JavaScript frameworks. Also, what is your background and from which route id you enter web development? 

Some articles on the subject:
* [Stop using CSS in JS for web development](https://medium.com/@gajus/stop-using-css-in-javascript-for-web-development-fa32fb873dcc)
* [CSS in JS - The Argument redefined](https://medium.com/@steida/css-in-js-the-argument-refined-471c7eb83955)
* [All you need to know about CSS in JS](https://hackernoon.com/all-you-need-to-know-about-css-in-js-984a72d48ebc)

Thank you for your time!
Web Scraping with Python BeautifulSoup and Requests
Tags: python, beautifulsoup, requests, webscraping
Published: 2017-12-20 10:01:36

---
title: Web Scraping with Python BeautifulSoup and Requests
published: true
description: Web scraping with Python, BeautifulSoup and Requests libraries.
tags: #Python #BeautifulSoup #Requests #WebScraping
---

This is an overview of a blog post I recently wrote about how to scrap web pages using Python BeautifulSoup and Requests libraries.


###What is Web Scraping:
Web scraping is the process of automatically extracting information from a website. Web scraping, or data scraping, is useful for researchers, marketers and analysts interested in compiling, filtering and repackaging data.

A word of caution: Always respect the website’s privacy policy and check robots.txt before scraping. If a website offers API to interact with its data, it is better to use that instead of scraping.

###Web Scraping with Python and BeautifulSoup:
Web scraping in Python is a breeze. There are number of ways to access a web page and scrap its data. I have used Python and BeautifulSoup for the purpose.

In this example, I have scraped college footballer data from ESPN website.

###The Process:
* Install requests and beautifulsoup libraries
* Fetch the web page and store it in a BeautifulSoup object. 
* Set a parser to parse the HTML in the web page. I have used the default html.parser
* Extract the player name, school, city, playing position and grade.
* Appended the data to a list which will be written to a CSV file at later stage.
 

![Python BeautifulSoup Tutorial: Web Scraping In 20 Lines Of Code](http://www.kashifaziz.me/wp-content/uploads/2017/10/college-footballer-data-scraping-python-beautifulsoup-code.jpg)

###The Code:
{% gist
https://gist.github.com/kashaziz/dbdb8f39e5c99a8a5bcbfdc01553d66b.js %}


[Detailed blog post is available here.] (http://www.kashifaziz.me/web-scraping-python-beautifulsoup.html/)
Who of you use getters & setters and when?
Tags: discuss, begginers, oop, php
Published: 2017-12-20 09:34:41

---
title: Who of you use getters & setters and when?
published: true
description: 
tags: #discuss #begginers #oop #PHP
---


I've been developing commercially for coming up to a year now and work in a very small team of developers. The majority of what I have learnt with PHP I learnt myself but I have also learnt a lot in the last 6 months on an Open Uni course studying OOP with Java. 

I wouldn't say I have come across much PHP material that specifically mentions the use of getters and setters, neither does the existing code base at the company I work for seem to use getters and setters. On the flip side while studying Java with the OU they seem to be pushing getters and setters religiously. 

I am working on a new project and many of the classes I will be writing will be brand new classes introducing completely new functionality. So my question here is what is your experience with getters & setters and do you guys use them religiously regardless of language?

Thanks in advance for your input.