teleren/devto huggingface dataset:
How to Encode and Decode URL in PHP
Tags: php
Published: 2022-04-18 12:14:45

---
title: How to Encode and Decode URL in PHP
published: true
date: 2018-09-19 11:20:38 UTC
tags: PHP
canonical_url: https://stacktips.com/tutorials/php/encode-and-decode-url-in-php
---

This post explains how to **encode and decode** URL using PHP. PHP supports encoding and decoding of URL by providing some built-in functions. Encoding is required before sending URL data to query string or to a function which might dynamically work on this URL data. And then, this data will be decoded into its original form, after receiving it in target PHP page or function.

## **PHP Encode and Decode URL Example** :

First, let us create an HTML file and save it as `sample.html`

**sample.html **

```
<form method="post" action="encode_decode.php">
               <input type="text" name="url" placeholder="Enter URL To Encode">
               <input type="submit" name="encode_url" value="ENCODE">
            </form><form method="post" action="encode_decode.php">
               <input type="text" name="url" placeholder="Enter URL To Decode">
               <input type="submit" name="decode_url" value="DECODE">
            </form>
```

Let us now, create a PHP file to encode and decode URL.

**encode\_decode.php**

```
<?php if(isset($_POST['encode_url']))
   {
    $url = $_POST['url'];
    $encodedUrl = urlencode($url);
    $converted_url=$encodedUrl;
   }   
   
   if(isset($_POST['decode_url']))
   {
    $url = $_POST['url'];
    $decodedUrl = urldecode($url);
    $converted_url=$decodedUrl;
   }
?>

```

Lets see the simple example to encode and decode URL in PHP:

```
$url = "https://www.example.com/p/selenium.html";
//encoding URL
$encodedUrl = urlencode($url);
echo $encodedUrl;
//Prints: https%3A%2F%2Fwww.example.com%2Fp%2Fselenium.html

//decoding URL
echo urldecode($encodedUrl);
//Prints: https://www.example.com/p/selenium.html
```

This all about encoding and decoding URL in PHP. Thank you for reading this article, and if you have any problem, have another better useful solution for this article, please write a message in the comment section.


The post [How to Encode and Decode URL in PHP](https://stacktips.com/tutorials/php/encode-and-decode-url-in-php) first appeared on [Stacktips](https://stacktips.com).
SecItemDelete without limits
Tags: objectivec
Published: 2019-01-31 20:15:37

---
title: SecItemDelete without limits
published: true
tags: objectivec
canonical_url: https://zeitschlag.net/secitemdelete-without-limits/
---

Together with a friend I'm working on a small app for iOS written in good ol' Objective-C. It's a (another) small timetracking application with an optional backend.

The credentials for the backend are to be stored in the Keychain. Users should also be able to delete those credentials again, of course. To remove things from the Keychain, I used `SecItemDelete` ([Documentation](https://developer.apple.com/documentation/security/1395547-secitemdelete?language=objc)) with the the same, following query-`NSDictionary` as for `SecItemCopyMatching` ([Documentation](https://developer.apple.com/documentation/security/1398306-secitemcopymatching?language=objc)):

```
@{
    (__bridge NSString *)kSecClass: (__bridge NSString *)kSecClassGenericPassword,
    (__bridge NSString *)kSecMatchLimit: (__bridge NSString *)kSecMatchLimitOne,
    (__bridge NSString *)kSecAttrService: kKOKeychainKeyService
}
```

But it didn't work: When retrieving things from the Keychain, everything was fine. But when using the query for for deletion, Xcode kept telling me, that the `OSStatus` was `-50`:

> One or more parameters passed to the function were not valid. — [osstatus.com](https://www.osstatus.com/search/results?platform=all&framework=Security&search=-50#)

It took me some time to find out, but `SecItemDelete` doesn't work with `kSecMatchLimitOne`. On the one hand, this does make sense, as you don't know, which item would be deleted. On the other hand, the documentation tells me:

> See the SecItemCopyMatching function for information about how to construct a search dictionary. — [Documentation](https://developer.apple.com/documentation/security/1395547-secitemdelete?language=objc#discussion)

What it doesn't say is, that this `kSecMatchLimit`-behaviour is different: To limit deletions, you have to specify an additional key.

After removing `kSecMatchLimit` from the dictionary, deleting Keychain-items worked.

Thanks again for reading!
golangのechoで静的なサイトを建てるならNowがお手軽という話
Tags: docker, go, now
Published: 2018-09-19 10:40:04

---
title: golangのechoで静的なサイトを建てるならNowがお手軽という話
published: true
description: 
tags: docker, golang, now
---

NowというPaasが、golangをデプロイするのにお手軽だということがわかった。

<blockquote class="twitter-tweet" data-lang="ja"><p lang="ja" dir="ltr">golang echo でサーバ書いて Dockerfile 書いて now でアップロードしてみた。ドメインは適当に取って now ln で alias 張った。めちゃ簡単だし LE も作ってくれる。便利やん。<a href="https://t.co/fXT7yR2BZC">https://t.co/fXT7yR2BZC</a></p>&mdash; mattn (@mattn_jp) <a href="https://twitter.com/mattn_jp/status/1042078292944093184?ref_src=twsrc%5Etfw">2018年9月18日</a></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

## 公開するまでの手順

- Nowのアカウントを作成する
- DotTkで無料ドメインを取得する。
  - Nameserverにzeit.worldを４つくらい指定しておく。
- Dockerfile, main.go, now.jsonを作成する。
  - 取得したドメインをnow.jsonのaliasに記述しておく。
- nowで一旦デプロイできるか確認する。
- 問題なければnow aliasでproductionとしてデプロイする。

## source code

[こちら](https://github.com/fk2000/docker-go-now)
How do you contribute to opensource on GitHub ?
Tags: discuss, github, opensource
Published: 2018-09-17 16:05:28

---
title: How do you contribute to opensource on GitHub ?
published: true
description: A general method to code together in GitHub
tags: discuss, github, opensource
---
This is my third post and I want to thank you all for the motivational discussions we are haveing here in dev.to

"[How do you commit](https://dev.to/nazimboudeffa/how-do-you-commit-in-github--4h92)" was just an amazing post for ma that have let me know how everyone is using git in GitHub, so now it's time to go ahead

In fact, I like to discuss on slack and discord in some projects like [phaserjs](http://phaser.io) or [atom](http://atom.io) and as I have discovered [gitkraken](https://www.gitkraken.com/) it is a chance to just watch the devs and continue until I find a way to write an article on a general method to contribute to opensource on GitHub

What I can say for the moment is that watching the commits on gitkraken is really cool because we have a general view of what is going on every time a commit is made

##It is about to FORK and PR not just to CLONE

In the image bellow I have just cloned from the origin to a folder in a second drive, that I have just called GitHub and I don't touch the code, just watching the commits

To contribute I have to FORK and CLONE then PR, and before that I have to play a bit with the code, so, How do you contribute to opensource on GitHub ?

![PhaserJS commits in Gitkraken by direct cloning](https://thepracticaldev.s3.amazonaws.com/i/prgmf35ydmy7lupmgd2r.gif)
Revenge Hacking Is Hitting the Big Time
Tags: security, hacking, hackers, devsecops
Published: 2018-09-19 09:50:09

---
title: "Revenge Hacking Is Hitting the Big Time"
published: true
description: "Companies are hacking back against cybercriminals to try to prevent—or at least limit the damage of—Equifax-style disasters. One problem: It’s not all that legal."
tags: security,hacking,hackers,devsecops
---

Hacking back may become supported in legal terms as per https://www.thedailybeast.com/inside-the-shadowy-world-of-revenge-hackers meaning that if your organization is hacked you can retaliate and  try to hack the hackers that hacked you.

It seems this is already done by several organizations and that is an open secret in the security community.

What are your toughs on this?
Installing Spark on Ubuntu in 3 Minutes
Tags: pyspark, python, spark
Published: 2023-04-29 21:26:50

---
title: Installing Spark on Ubuntu in 3 Minutes
published: true
date: 2018-09-19 08:24:30 UTC
tags: pyspark,python,spark
canonical_url: https://mikestaszel.com/2018/09/19/installing-spark-on-ubuntu-in-3-minutes/
---

One thing I hear often from people starting out with Spark is that it’s too difficult to install. Some guides are for Spark 1.x and others are for 2.x. Some guides get really detailed with Hadoop versions, JAR files, and environment variables.

So here’s yet another guide on how to install Apache Spark, condensed and simplified to get you up and running with Apache Spark 2.3.1 in 3 minutes or less.

All you need is a machine (or instance, server, VPS, etc.) that you can install packages on (e.g. “sudo apt” works). If you need one of those, check out [DigitalOcean](https://m.do.co/c/18e08da59ad4). It’s much simpler than AWS for small projects.

First, log in to the machine via SSH.

Now, install OpenJDK 8 (Java):

```
sudo apt update && sudo apt install -y openjdk-8-jdk-headless python

```

Next, download and extract Apache Spark:

```
wget http://www-us.apache.org/dist/spark/spark-2.3.1/spark-2.3.1-bin-hadoop2.7.tgz && tar xf spark-2.3.1-bin-hadoop2.7.tgz

```

Set up environment variables to configure Spark:

```
echo 'SPARK_HOME=$HOME/spark-2.3.1-bin-hadoop2.7' >> ~/.bashrc
echo 'PATH=$PATH:$SPARK_HOME/bin' >> ~/.bashrc
echo 'export PYSPARK_PYTHON=python3' >> ~/.bashrc
source ~/.bashrc
```

That’s it – you’re all set! You’ve installed Spark and it’s ready to go. Try out “pyspark”, “spark-submit” or “spark-shell”.

Try running this inside “pyspark” to validate that it worked:

```
spark.createDataFrame([{"hello": x} for x in range(1000)]).count() # hopefully this equals 1000
```
<!--kg-card-end: html-->
Writing modular software using Go plugins
Tags: go, programming, software, modules
Published: 2018-09-25 15:22:33

---
title: Writing modular software using Go plugins
published: true
tags: go, programming, software, modules
cover_image: https://domenicoluciani.com/assets/images/covers/gopher2.jpg
---

The 1.8 version of Go bring with it the ability to writing modular software using plugins, how?

Each plugin is compiled as shared object library that can be loaded at runtime, interesting, right? [Let's read how it works!](https://domenicoluciani.com/2018/09/19/writing-modular-software-using-go-plugins.html)
if-then, a statement in Java; but an expression in Kotlin
Tags: kotlin, beginners
Published: 2018-09-30 06:16:02

---
title: if-then, a statement in Java; but an expression in Kotlin
published: true
tags: kotlin, beginner
canonical_url: https://www.workingdev.net/2018/09/kotlin-if-then.html
description: Kotlin's if-then construct is almost the same as Java's, but in Kotlin, if-then is an expression, not a statement
cover_image: https://thepracticaldev.s3.amazonaws.com/i/0j91apruz4i8j8jdckjd.jpg
---

The _if_ construct in Kotlin works almost the same as in Java.

```kotlin
val theQuestion = "Doctor who?"
val answer = "Theta Sigma"
val correctAnswer = ""

if (answer == correctAnswer) {
 println("You are correct")
}
```

Another example, this time, let's use the `else if` and `else` clause.

```kotlin
val d = Date()
val c = Calendar.getInstance()
val day = c.get(Calendar.DAY_OF_WEEK)

if (day == 1) {
 println("Today is Sunday")
}
else if (day == 2) {
 println("Today is Monday")
}
else if ( day == 3) {
 println("Today is Tuesday")
}
else {
  println("Unknown")
}
```

So far, it looks a lot like how you would you do it in Java. Doesn't it? What's different in Kotlin is, the `if` construct isn't a statement, it's an expression. Which means, you can assign the result of the `if` expression to a variable. Like this

```kotlin
val theQuestion = "Doctor who"
val answer = "Theta Sigma"
val correctAnswer = ""

var message = if (answer == correctAnswer) {
 "You are correct"
}
else{
 "Try again"
}
```

If you have only one statement (each) on the if and else block, you can even shorten the code, like this

```kotlin
var message = if (answer == correctAnswer) "You are correct" else "Try again"
```
 ![](http://feeds.feedburner.com/~r/WorkingDev/~4/FIKDlWIJNVM)
The comment-pocalypse | Part 1
Tags: comments, devhelp
Published: 2018-09-19 05:32:28

---
title: The comment-pocalypse | Part 1
published: true
description: 
tags: comments, devhelp
canonical_url: https://code-vault.net/articles/comments-part1.php
---

*Originally posted on [CodeVault](https://code-vault.net/articles/comments-part1.php)*

There are quite a few conventions when it comes to commenting your code. Let's break them down and see how good/bad they are.

First is the **comment all your methods** convention. Why would you do that? So everyone knows what your code does and how to use it. The upsides are that:
 * badly naming methods becomes less problematic
 * hard to understand methods are usually easier to understand
 * in case of examples, it is really easy to learn how to use

This all sounds fine and dandy but commenting all your methods is a double-edged sword. Let's look at an example:

```java
/**
 * Gets all the hardware of the type and brand given.
 * Searches for substring *brand* inside each hardware's brand name.
 * @param type the type of hardware
 * @param brand the brand to search for
 * @returns a list of hardware
 * Example: getHardwareOfTypeAndBrand(HardwareType.Keyboard, "Das") 
 *          returns List with dasKeyboard1 and dasMechKeyboard2
 */
public List<Hardware> getHardwareOfTypeAndBrand(HardwareType type, String brand) { ... }
```

I think we can all agree that having comments and examples at least **looks** nice. But what about their usability? Does the comment:

```
 * Gets all the hardware of the type and brand given.

 * @param type the type of hardware
 * @param brand the brand to search for
 * @returns a list of hardware
```

tell us more about the method than:

```java
public List<Hardware> getHardwareOfTypeAndBrand(HardwareType type, String brand)
```

The answer: No. And here we get to the first issue: **REDUNDANCY**. And you know what happens when you have redundancy in your code? When one change occurs in one place you will have to change it in another. 

Same goes for comments. If we were to update our method and add another parameter we would also have to change our comment, otherwise our comment becomes **MISLEADING**. 

Misleading comments are our second issue. Especially when we also have examples. 
But don't we have tools and plugins that help us updating our comments when the signature of the method changes? Yes we do, but that means more time investment in something that, at the end of the day, will be redundant. 

Imagine changing our method from, instead of searching for brands that contain the given string we would check if the brands name corresponds exactly. 

You should also change the comment. But would you, when it's 8 PM and in 10 minutes you have a deploy to make? Couple that with there being no way of checking if the example is valid and you have got a recipe for disaster. This is where this comment:

```
Searches for substring *brand* inside each hardware's brand name.
```

can also become misleading.

Next part we will discuss about the other conventions and their pros and cons.
Learning Algorithms with JS, Python and Java 8: Sentence Capitalization
Tags: beginners, javascript, python, java
Published: 2018-09-19 00:51:42

---
title: Learning Algorithms with JS, Python and Java 8: Sentence Capitalization
published: true
description: 
tags: beginners, javascript, python, java
---

It's been a while since I posted the last article. Today's is a nice and simple one for rehab.

This series of articles follows Stephen Grider's [Udemy course](https://www.udemy.com/coding-interview-bootcamp-algorithms-and-data-structure/) in three different languages. JavaScript solutions are [by Stephen](https://github.com/StephenGrider/AlgoCasts/blob/master/completed_exercises/). I try to "translate" them into Python and Java.


Today's question is:

> --- Directions
> Write a function that accepts a string.  The function should
> capitalize the first letter of each word in the string then
> return the capitalized string.
> --- Examples
>   capitalize('a short sentence') --> 'A Short Sentence'
>   capitalize('a lazy fox') --> 'A Lazy Fox'
>   capitalize('look, it is working!') --> 'Look, It Is Working!'

#1: Concise solution using built-in libraries

JavaScript:
```
function capitalize(sentence) {
    const words = [];

    for (let word of sentence.split(' ')) {
        words.push(word[0].toUpperCase() + word.slice(1));
    }

    return words.join(' ');
}
```

Python:
```
def capitalize1(sentence: str) -> str:
    words = [word[0].upper() + word[1:] for word in sentence.split()]
    return ' '.join(words)
```

```
def capitalize2(sentence: str) -> str:
    return ' '.join([word.capitalize() for word in sentence.split()])
```

```
def capitalize3(sentence: str) -> str:
    return sentence.title()
```

Java:
```
import java.util.LinkedList;
import java.util.List;

public static String capitalize(String sentence) {
	List<String> words = new LinkedList<>();

	for (String word : sentence.split(" ")) {
		words.add(String.valueOf(word.charAt(0)).toUpperCase() + word.substring(1));
	}

	return String.join(" ", words);
}
```

#2: Brute force solution using a loop

JavaScript:
```
function capitalize(sentence) {
    let result = sentence[0].toUpperCase();

    for (let i = 1; i < sentence.length; i++) {
        if (sentence[i - 1] === ' ') {
            result += sentence[i].toUpperCase();
        } else {
            result += sentence[i];
        }
    }

    return result;
}
```

Python:
```
def capitalize(sentence: str) -> str:
    result = ''

    for i, char in enumerate(sentence):
        if i == 0 or sentence[i - 1] == ' ':
            result += char.upper()
        else:
            result += char

    return result
```

Java:
```
public static String capitalize(String sentence) {
	StringBuilder result = new StringBuilder(String.valueOf(sentence.charAt(0)).toUpperCase());
	
	for (int i = 1; i < sentence.length(); i++) {
		if (sentence.charAt(i - 1) == ' ') {
			result.append(String.valueOf(sentence.charAt(i)).toUpperCase());
		} else {
			result.append(sentence.charAt(i));
		}
	}
	
	return result.toString();
}
```

Thank you for reading so far. I hope to see you again soon!
When signing up or logging into an app, do you prefer OAuth (authentication w/social media account) or email sign up/sign in?
Tags: discuss
Published: 2018-09-19 04:04:48

---
title: When signing up or logging into an app, do you prefer OAuth (authentication w/social media account) or email sign up/sign in?
published: true
tags: discuss
---

I'm in the process of adding OAuth support for an app I'm making but it's my first time doing it so I'm wondering if it's worth the time and effort?
Help Me Name My New Computer
Tags: help, funny
Published: 2018-09-19 03:35:25

---
title: Help Me Name My New Computer
published: true
description: I'm getting a new computer and it needs a name!
tags: help, funny
cover_image: https://thepracticaldev.s3.amazonaws.com/i/45oql67ipvmhs0vzg86y.jpg
---

Calling all DEV's, funny people, and general creatives!  I need your help!

I'm getting a new computer.

**It needs a name.**

## Background

For my current CS class, one of the projects is to install some kind of Linux on something and document the process.  I could have used a Virtual Machine of some kind, or maybe a Raspberry Pi.  But I've done that, and I wanted the full experience.  Also, I think I can write it off under books and supplies.  😬

So, I bought [this little friend](https://amzn.to/2pkwqZj) (heads up, shameless affiliate link).  11.6" screen, 2.5GHz, 4GB RAM, and 32GB storage + a SD slot.  Comes with a year of Office 365 which is a neat bonus.  But, it needs a name.  And I'm enlisting your help to do it.

## Requirements

Feel free to make it gendered or not.  Keep it PG.  For reference, my Macbook is named `janice` because naming things and pets with generic human names is funny to me.  Also, it seems like the name of a librarian or some other person who is generally dependable and knows a lot of stuff.

One thought I've already had: I'm going to be installing Debian on it, and, while it's not super clever or original, I'm kind of liking the name `debbie`.  Let me know if you like that.  Otherwise, let me hear your suggestions!

Thanks, friends!
What I Learnt After Being Disconnected For 10 Days
Tags: internet, experience
Published: 2018-09-19 03:29:53

---
title: What I Learnt After Being Disconnected For 10 Days
published: true
description: My Experience of staying far away from internet for more than 10 days
tags: internet, experience
cover_image : https://thepracticaldev.s3.amazonaws.com/i/qbcamo1qu44pt4l9wjvq.jpg
---

I was that kind of guy who uses lots of internet (Actually Too Much..) but unfortunately my phone's charging port got damaged so I had no way left other than sending it to Service Center. The guy there told me it's gonna take a while.

> ### I knew for these days I'll not be able to use internet so I'll not able to upload any articles.

![](https://thepracticaldev.s3.amazonaws.com/i/qbcamo1qu44pt4l9wjvq.jpg)

Actually I use internet on my pc via USB Tethering from my phone , so there was no chance of uploading new contents.

> ### I learnt few things these days.

I was disconnected, left with a old keypad phone. Actually it helped to get rid of overuse of internet and concentrate more on my studies. I started visiting nearby places more often.  I started hanging out with my friends with phone calls rather than texting.

I usually spend most of time building. But as the internet was gone i was creating designs of my inventions by hand with pen and pencil. 

As my resources was limited , I was kinda lost for first few days but then after things got better.

Inventor Palash Bauri returned, I built some new gadgets. I read more books.

> ### Something inside me was changed. My Inventor self was on front again.

I think , Everybody who uses internet a lot should take a break and enjoy the surroundings. Just Try it once!😉

---
If You Like My Work (My Articles, Stories, Softwares, Researches and many more) Consider [Buying Me A Coffee ☕](https://www.buymeacoffee.com/palash) 🤗
Fearless by loving failure - Isa Silveira - Developer Discussions
Published: 2018-09-19 01:10:47

---
title: Fearless by loving failure - Isa Silveira - Developer Discussions
published: true
description: Fantasic talk! Loved to part about developing for older slower devices and enabling greater access people in lower socioeconomic areas. https://youtu.be/F_QdJ-spWgg
tags: 
---