teleren/devto huggingface dataset:
Seamlessly integrate Hashids with Django
Tags: django, hashids
Published: 2020-08-28 04:50:45

---
title: Seamlessly integrate Hashids with Django
published: true
description: What is hashids, why it's useful, the challenges I had when using it in Django, and how I solved them.
tags: django, hashids
canonical_url: https://shenli.dev/2020/08/26/django-hashids.html
//cover_image: https://direct_url_to_image.jpg
---

# Introduction
Hashids is a library that maps an integer to a string with provided `salt`, `alphabet`, and `min_length`. For example, it can turn integer `1` into `"r87f"` and convert it back when required.

It is a way to obfuscate ids and is particularly useful when you don't want anyone to iterate through everything in your database by going through all the ids. 

I have used Hashids a few times with Django. And every time I need to expose the `id` field, I would convert the `id` value to a hashids by calling something like this:
```python
from utils import hashids

def to_json(obj):
    exposed_id = hashids.encode(obj.id)
    ...
    return {
        'id': exposed_id,
        ...
    }
```
And everywhere that `exposed_id` is used I need to convert it back, which ended up as a lot of code in different places.

Another issue with this approach is that it's hard to use different configurations, such as salt and alphabet, for different models. The `exposed_id` for different models with the same actual `id` will be the same.

There are some existing projects that integrate the two, but they are more intrusive than I would like them to be. As they usually actually writes to the database, instead of just encode/decode between obfuscated id and integer ids on the fly.

This leads to this small library I made with less than 100 lines of code, called [`django-hashids`][django-hashids].

# django-hashids
[`django-hashids`][django-hashids] integrates Django with Hashids by introducing a "virtual" field to Django models. It is "virtual" because it does not have a column in the database but allows people to query it as if there were an actual database column.

Here's a simple example:
```python
class TestModel(Model):
    hashid = HashidsField(real_field_name="id")

instance = TestModel.objects.create()
instance2 = TestModel.objects.create()
instance.id  # 1
instance2.id  # 2

# Allows access to the field
instance.hashid  # '1Z'
instance2.hashid  # '4x'

# Allows querying by the field
TestModel.objects.get(hashid="1Z")
TestModel.objects.filter(hashid="1Z")
TestModel.objects.filter(hashid__in=["1Z", "4x"])
TestModel.objects.filter(hashid__gt="1Z")  # same as id__gt=1, would return instance 2

# Allows usage in queryset.values
TestModel.objects.values_list("hashid", flat=True) # ["1Z", "4x"]
TestModel.objects.filter(hashid__in=TestModel.objects.values("hashid"))
```
As you can see, it allows you to use `TestModel.hashid` like a real field with all the sensible lookups but queries are proxies to `id` field with encoding/decoding happening on the fly providing a seamless experience.

> For more usage and configuration options please visit [django-hashids on github][django-hashids]

[django-hashids]:https://github.com/ericls/django-hashids
Magento 2 Delivery Date Extension
Tags: php, devops, devpride
Published: 2020-08-28 04:40:27

[Magento 2 Delivery Date](https://www.mageants.com/delivery-date-for-magento-2.html) is best to implement as it allows your customers to schedule the delivery date and time for the delivery of their purchased product.

**Key Features:**

1. Customers can schedule the product delivery date & time as per their convenience.

2. Admin can exclude non working days from delivery options like holidays, weekends, etc.

3. Provide a special comment box for buyers to add any custom message related to their product delivery.

4. Admin can set a limit to maximum and minimum delivery intervals.

5. Supports the “Call Me before Delivery” option for customers.
Best Chrome Extension to test Responsive design
Tags: css, design, webdev
Published: 2020-08-28 04:33:51

Hope you guys are doing great.

Here is something I found today.

Chrome extension to test the responsive design easily, with the full ability to debug the code using Developer tools.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pa492le24kxcss9rnygw.png)
check this out. It's totally free of cost.
Note: I am not the sponsor of this extension :)


https://chrome.google.com/webstore/detail/mobileresponsive-web-desi/elmekokodcohlommfikpmojheggnbelo


I hope this helps someone. have a great day
The shortest way to achieve responsive font-size
Tags: design, web, css
Published: 2020-08-28 04:23:44

Hello guys, hope you are doing well, 

Today, I learned something that I was trying to achieve unconsciously for almost 2 months.

Coming to the point, here is the shortest path to achieving responsive font-size in CSS, I have tested it and used it, so no a big problem here.


```
.quickbar {
font-size: calc(0.9rem + 1vmin);
}

```
I have used rem as font size unit, you can use a pixel or anything you want.

here is the definition of terms used above, in case you are not aware of those.
```
vmin is the minimum between the viewport's height or width in percentage depending on which is smaller
```

Live demo:

https://codepen.io/csuwildcat/pen/qOqVNO


References:

https://stackoverflow.com/a/32805276
CLI |> Compress and Decompress via CLI
Tags: quickanswer, cli, tar, zip
Published: 2020-08-28 04:09:18

> IF YOU JUST SOLVED SOME PROBLEM, WELCOME TO DM **qaRabbit** ON [TWITTER](https://twitter.com/qaRabbitx), OR CREATE A PULL REQUEST IN [GITHUB REPO](https://github.com/supeterlau/quickanswer).

## macOS

- file.zip

    extract to the current directory

    `unzip file.zip`

    extract to the target directory

    `unzip file.zip -d target_dir_path`

    compress to file.zip

    `zip file path1 path2 path3`

- file.tar (archive, no compress)

    extract to the current directory

    `tar -xvf file.tar`

    extract to target_dir_path (must be created first)

    `mkdir -p target_dir_path && tar -C target_dir_path -xvf file.tar`

    compress path

    `tar -cvf file.tar path1 path2`

- file.tar.gz file.tgz

    _**tar.gz** file is a **Tar archive** compressed with **Gzip**_

    extract to the current directory

    `tar -zxvf file.tar.gz`

    extract to target_dir_path (must be created first)

    `mkdir -p target_dir_path && tar -C target_dir_path -zxvf file.tar.gz`

    compress path

    `tar -czvf file.tar.gz path1 path2 ...`

    compress with exclude

    `tar -czvf file.tar.gz path --exclude=sub_path1 --exclude=sub_path2`

    `tar -czvf file.tar.gz path --exclude={sub_path1, sub_path2}`

    `tar -czvf file.tar.gz path --exclude=*.ext`

- file.tar.xz

    _**tar.gz** file is a **Tar archive** compressed with **Xz** a LZMA based compress algorithm_

    tar auto-detects compression type and extracts the archive

    `tar -xf file.tar.xz`

- file.tar.bz2 file.tbz

    _**tar.bz2** file is a **Tar archive** compressed with **Bzip2**_

    extract to the current directory

    `tar -xvf file.tar.bz2`

    extract to target_dir_path (--directory, -C; must be created first)

    `mkdir -p target_dir_path && tar -xvf file.tar.bz2 -C target_dir_path`

    extract specific files

    `tar -xf archive.tar.bz2 file1 file2 dir1 dir2`

    `tar -xf archive.tar.bz2 --wildcards '*.md'`

    extract from stdin

    `wget -c ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2 -O - | sudo tar -xj`

    list archive content (--list, -t)

    `tar -tvf file.tar.bz2`

    compress path

    `tar -cjvf file.tar.bz2 path1 path2`

## GNU/Linux

<hr>

*References*:

- https://www.cyberciti.biz/faq/linux-howto-unzip-files-in-root-directory/
- https://www.hostingmanual.net/zipping-unzipping-files-unix/
- https://linuxize.com/post/how-to-create-and-extract-archives-using-the-tar-command-in-linux/
- https://linuxize.com/post/how-to-extract-unzip-tar-bz2-file
- https://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux/
- https://www.howtogeek.com/248780/how-to-compress-and-extract-files-using-the-tar-command-on-linux/
- https://unix.stackexchange.com/questions/25311/create-target-directory-when-extracting-tarball
Journey to building a SaaS Product– #1
Published: 2020-08-28 03:03:11

COVID 19 has been a disaster to almost every business & person, and my startup was not spared. Being a python & a web developer, I can build anything with my skill set. I just needed to find an opportunity.
The next question I had to ask myself was –
How do I find the opportunity?

## The opportunity.
What most indie developers like to do is think about their app first, what features to include, what’s the requirements, what is the time to production, etc.

Being a businessman & a Dev, I thought first of the opportunity, it’s pros, it’s cons & lastly the market that I intend to target. As to me, customers come first then the app and then the monetary aspects.

While searching for an opportunity, I stumbled upon ‘Email Marketing’. Email marketing for the most part has been driven by analytics, data, automation, and personalization. It’s one of the most underrated methods in Digital Marketing as it requires in-depth knowledge about your target audience than any other technique, but has the opportunity to become the largest conversion technique in the shortest amount of time.

A great copy, a simple email sending tool, and knowledge about your targets are all you really need to succeed at Email Marketing.
Tools like Mailchimp & Sendgrid provide with everything at an extravagant cost. Upon closer inspection using AWS’s Cost Estimates & bits of Excel data modeling.

I found a few points –
1. Price to cost ratio was manageable for a small startup like mine.
2. I can offer ‘core’ features at a really low cost ~$10 for 10,000 to 50,000 emails.
3. A customer-centric approach is the best way forward.
4. Automation will be built at a later stage as I will need data as to how much of that solution is beneficial for my customers.
5. Drag and drop Templates are great to use but have issues with Email Clients. In the first release, I will have to keep this solution aside until I find a complete answer to this problem.

## Where to begin?
This question puzzled me for the longest time. The answer was simple. Design a Plan Of Action.

Will be continued in the next part. Thanks for reading 😁
Conditionally rendering in React with ternary operator
Tags: beginners, codenewbie, react, javascript
Published: 2020-08-28 03:58:36

This is a common technique when you want to render one out of two components based on a condition (for example when a state or a prop changes). If you have multiple conditions i advise you to use `switch`.

In the below example, you can change the greeting text by clicking the button which will change the state of `buttonClicked`.

[Link to the live demo](https://codesandbox.io/s/sparkling-bird-wi7e3?file=/src/App.js)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sdo9l4pjauq7l2l80u2b.png)
FYP-Log 000 of #100DaysOfFYP
Tags: beginners, project, concepts, mathematics
Published: 2020-08-28 03:31:04

**FYP-log 000, Earth-date 27-08-2020**

I opened LinkedIn at my browser to check out my notifications and while at it, I stumbled upon a post written by a friend of mine on his little challenge to update day by day on his academic final year project.

So I went through the daily updates and it got me thinking what if I do what he does :challenging myself to update on the progress of my academic final year project and doing it in a set time-frame.

I believe this can be a way for me to be discipline and at the same time, improving my writing skills and to get use of this new platform.

I have always wanted to write about something and this can be it - *to write about my journey in developing my first Machine Learning-Creative project* 

![Alt text of image](https://media.giphy.com/media/rVbAzUUSUC6dO/giphy.gif)
<figcaption>I cannot wait!</figcaption>

I pray and wish to have the strength to maintain this journey as it will be fruitful in the end.

**FYP-Log 000 End**
August 28th, 2020: What did you learn this week?
Tags: weeklylearn, discuss, weeklyretro
Published: 2020-08-28 03:00:22

It's that time of the week again. So wonderful devs, what did you learn this week? It could be programming tips, career advice etc.

<center>

![Yoda wooping someone's butt](https://media.giphy.com/media/yDYAHbqe5DfyM/giphy.gif)

</center>

Feel free to comment with what you learnt and/or reference your TIL post to give it some more exposure.

{%tag todayilearned %}

And remember, if something you learnt was a big win for you, then you know where to drop it as well.👇👇🏻👇🏼👇🏽👇🏾👇🏿

{% link https://dev.to/devteam/what-was-your-win-this-week-4nfo %}

<center>

![Little kid making a fist as if to say "Yes!"](https://media.giphy.com/media/6brH8dM3zeMyA/giphy.gif)

Photo by [twinsfisch](https://unsplash.com/@twinsfisch?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/learning?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)
Emulate bash "history" but for iex
Tags: elixir, erlang
Published: 2020-08-16 07:06:24


Personally, I think the bash command, `history`, is a neat productivity tool. I use it all the time `history | grep` and I wanted the same thing in IEx as well.

To search through the history in IEx, you need to first enable it. Then either use **up** arrow keys or **ctrl + r** to search. That's cool but still not exactly what I need.

So, the first thing I had to do was to find the place where the history is stored.

```elixir
# run it in your IEx
:filename.basedir(:user_cache, "erlang-history")
```

The history files are written by erlang's `disk_log`, so there will be weird characters when you open it in your editor. My initial thought was, if the history is written by `disk_log:log/2` which uses `erlang:term_to_binary/1`, then I can read those history files with `erlang:binary_to_term/1`. But it turns out when writing history, `disk_log` appends some kind of weird binaries which you can find in `disk_log.hrl` eg `<<12,33,44,55>>`. So, I tried `disk_log:chunk/2` to parse it.

```elixir
# this will print the content of the history file with header
# in IEx, it will print charlists
# in erl, it will print strings

:disk_log.chunk(:'$#group_history', :start)

```

It did parse the history but it had weird headers and also didn't give me the whole content of all the history files.

```
{{:continuation, #PID<0.81.0>, {1, 52393}, []},
 [
   {:vsn, {0, 1, 0}},
``` 

I found a file called `group_history.erl`. It has two public api `load/0` and 'add/2'. The `load/0` api parsed and returned the whole history just as I wished.

```elixir
:group_history.load()
```


And then I finally wrote the rest of the code to emulate bash `history` command

```elixir
defmodule History do
  def search(term) do
    load_history()
    |> Stream.filter(&String.match?(&1, ~r/#{term}/))
    |> Enum.reverse()
    |> Stream.with_index(1)
    |> Enum.each(fn {value, index} ->
      IO.write("#{index}  ")
      IO.write(String.replace(value, term, "#{IO.ANSI.red()}#{term}#{IO.ANSI.default_color()}"))
    end)
  end

  def search do
    load_history()
    |> Enum.reverse()
    |> Stream.with_index(1)
    |> Enum.each(fn {value, index} ->
      IO.write("#{index}  #{value}")
    end)
  end

  defp load_history, do: :group_history.load() |> Stream.map(&List.to_string/1)
end
```
I have put this code in my `.iex.exs` file so that I can call it whenever I am in my IEx.

```elixir
History.search("map")
History.search()
``` 

## Hi there!!

Hi, I am looking for awesome opportunities to work with Elixir. If you are hiring or need a hand to finish your pet/side project then let's get connected. Here is my email sussyoung9[at]gmail[dot]com
Is Anyone Else Developing on Windows with WSL2?
Tags: discuss, webdev
Published: 2020-08-28 02:08:18

While I've always had a windows PC sitting around for casual use and playing video games, the developer experience always felt clunky.

Recently my Macbook was feeling sluggish and hot all the time, so I checked out WSL2 + Ubuntu + windows terminal and it's been so buttery smooth!

What are other peoples experiences?
Setup Clojure on Windows (WSL) or Linux
Tags: clojure
Published: 2020-08-28 02:02:54

---
title: Setup Clojure on Windows (WSL) or Linux
published: true
description: Setting up clojure development for windows is easy but everyone does things the hard way.
tags: clojure
//cover_image: https://direct_url_to_image.jpg
---

So I've been working through this book ["Clojure for the Brave and True"](https://www.braveclojure.com/) and I got a bit stuck trying to do setup for Windows. So here's what I did.

1. Use WSL.
2. Install Java in the terminal with: `sudo apt install openjdk-11-jdk`
3. Install leiningen with apt-get: `sudo apt-get install leiningen`

Boom, that's it and you're off the the races. You can use emacs like the book recommends but I just use VS Code (because it integrates easily with WSL) and [this extension](https://github.com/avli/clojureVSCode). REPL works great and you're off and learning with little fuss.

I found there to be very little information on how to set things up easily on Windows and having just started using Windows I don't know much about the packages and powershell so it felt nice and easy to do this with Linux. Hope I saved someone, even if its my future self, some setup time.
NFD Nightly Packages, Cross-Compiled for Raspberry Pi
Tags: actionshackathon
Published: 2020-08-28 01:57:05

### My Workflow

**NDN Forwarding Daemon (NFD)** is a network forwarder for [Named Data Networking (NDN)](https://named-data.net), a future Internet architecture.
The source code of this software is updated weekly, but the upstream project only provides binary releases for Ubuntu and it's only updated twice a year.
Therefore, I made a GitHub Actions workflow to automatically compile NFD software every week, for Debian, Raspberry Pi OS, and Ubuntu.

GitHub-hosted runners only have amd64 CPU architecture.
In order to compile for Raspberry Pi that use ARMv6/ARMv7/ARMv8 architecture, I use [Balena Docker images](https://www.balena.io/docs/reference/base-images/base-images-ref/) that support **cross-compiling via QEMU**.
QEMU is much slower than a normal cross compiler, but the results are more reliable.

Within the script, I use the `debuild` command to generate `.deb` packages that can be installed via APT. The generated `.deb` files are **stored as Artifacts**.

In order to avoid 6-hour timeouts, each *job* only compiles one source package. Since NFD depends on ndn-cxx, the NFD job uses `actions/download-artifact@v2` Action to download the result of the ndn-cxx job, installs the `.deb` files inside the Docker container, and then compiles the NFD source package.

The webpage associated with this project **uses the [GitHub REST API](https://docs.github.com/en/rest/reference/actions) to query recently completed builds**, and displays the links.

### Submission Category: 

This is not an official hackathon submission because it was created before the hackathon announcement. If it was, the category would be "maintainer must-haves" (for cross-architecture compiling) and "interesting IoT" (for compiling for the Raspberry Pi that is an IoT computer).

### Yaml File or Link to Code

Project homepage: https://nfd-nightly.ndn.today/
GitHub repository and workflow: https://github.com/yoursunny/NFD-nightly
Blog post: https://yoursunny.com/t/2020/NFD-nightly/

### Additional Resources / Info
what's it like to work as a team?
Published: 2020-08-28 01:45:48

The project that I'm currently working on is about a company that builds bridges to help people in Africa, and the problem that my team and I are trying to solve is for users and admins to have a better visualization to where bridges are built and the communities that those bridges help.

The first thing we did was decided what the functionality of the project was and then break the tasks into smaller features. On the Back-end we started with the tasks that the front-end developers on my team needed and sending fake data just so the could have something to work with. 
Here is a screenshot on what I've worked on

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0kucv2blmsbrmc0etmpd.png)

 
What we accomplished on this pull request was manipulated a large amounts of data about bridges and villages and joined them together to display where communities were served by building the bridges.

##Facing challenges
One challenge that we faced was that when we received the data, that data did not match with our data schema, what we decided to do was iterated over all the data and lowercase all the keys of the objects and removed all the spaces from them. after that we just overwrite the old keys to match with the ones from our schemas.

Here is an example of the code we wrote.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6x4x0lze2ep7mbjhdsa9.png)

## Currently in progress

A challenge we are facing is when sending the data to the front-end we need to somehow paginate the data because if we send the data as it is, it takes approximately 7 seconds for the front-end to receive the data. 

### shipped features

1. Created tables for the database.
2. Created migrations and seeds for the database.
3. Created CRUD operations for villages and bridges Routes.
4. Added documentation for API Routes.
5. Manipulated data to display bridge information with the communities it served.

One future feature I think we can implement if we get the coordinates of the village so we can display villages in the front-end on the map as well.
And there are a few things I think it may cause problems with the performance, that might be a fun challenge to work on.

Some of the feedback I received from my teammates was that I should ask for help sooner so I don't waste valuable time and what I'm doing to improve is reaching out for help sooner.

This project has been an amazing experience for me so far, I learned a lot of new things, and the experience to work as a team was incredible.
What I'm learning with live coding
Tags: elixir, live, programming
Published: 2020-08-28 01:38:11

Hello everyone 👩🏻‍💻 👨🏻‍💻,
It has been a week since I started doing live coding at Facebook where I learn Elixir. I started this as an experiment, doing something new is always challenging. 
I've already done two live streams.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sawsv60spptwjblfxmz1.jpeg)

I recommend everyone to do it at least one time in life. In my case I picked up a programming language that I've never used before and started learning it in front of everyone.
It's teaching me some great lessons, I've figured out that the path of learning can't be minutely planned, and you don't have to be ashamed to fail. Sometimes things work out and sometimes not.

It's also a great exercise to feel more encouraged to express yourself and on the other hand you can be helping people too. 😃
#30DaysOfCJS: Observing Node.js
Tags: community, javascript, node, observing
Published: 2020-08-28 00:41:40

---
title: #30DaysOfCJS: Observing Node.js
published: true
description: #30DaysOfCJS Day 26, Observing Node.js
tags: community, javascript, nodejs, observing 
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/nt1gluksapxd2i019gkb.png
series: 30DaysOfCJS
---

*This is a follow up post for Day 26 of* **#30DaysOfCJS**, *learn more about* **#30DaysOfCJS** *here* {% link jimcalliu/30daysofcjs-1jd3 %}

**Observing Node.js // James Snell // CascadiaJS 2018**

If you'd like to watch the talk, here is the Youtube link.
{% youtube C8dwQw7M8Pk %}