Are you over 18 and want to see adult content?
More Annotations
![A complete backup of www.livehindustan.com/entertainment/story-indian-idol-11-finale-live-update-sunny-hindustani-rohit-raut-adr](https://www.archivebay.com/archive2/8a27a1c1-4440-4ac0-94b5-ebd37fad2423.png)
A complete backup of www.livehindustan.com/entertainment/story-indian-idol-11-finale-live-update-sunny-hindustani-rohit-raut-adr
Are you over 18 and want to see adult content?
![A complete backup of gs24.pl/przy-osiedlu-nad-rudzianka-powstanie-kolejny-kosciol-radni-glosowali-ws-kosciola-nad-rudzianka-radn](https://www.archivebay.com/archive2/5f0333c1-690e-4ee4-8c9d-4c4647cfec96.png)
A complete backup of gs24.pl/przy-osiedlu-nad-rudzianka-powstanie-kolejny-kosciol-radni-glosowali-ws-kosciola-nad-rudzianka-radn
Are you over 18 and want to see adult content?
![A complete backup of polskieradio24.pl/5/1222/Artykul/2462385](https://www.archivebay.com/archive2/f4732feb-48f1-41e1-8224-b47ed972c2e5.png)
A complete backup of polskieradio24.pl/5/1222/Artykul/2462385
Are you over 18 and want to see adult content?
![A complete backup of www.indiatoday.in/sports/football/story/manchester-united-vs-watford-premier-league-reach-5th-spot-on-premi](https://www.archivebay.com/archive2/a46e45ad-c32b-4800-ad1c-db7788675b45.png)
A complete backup of www.indiatoday.in/sports/football/story/manchester-united-vs-watford-premier-league-reach-5th-spot-on-premi
Are you over 18 and want to see adult content?
![A complete backup of www.chinatimes.com/realtimenews/20200225000018-260404](https://www.archivebay.com/archive2/06e97d6c-8360-47b8-998d-4fc05c152bb8.png)
A complete backup of www.chinatimes.com/realtimenews/20200225000018-260404
Are you over 18 and want to see adult content?
![A complete backup of eurosport.tvn24.pl/pilka-nozna](https://www.archivebay.com/archive2/3b9e980a-7e68-4ed8-bf60-ba1ed6b914da.png)
A complete backup of eurosport.tvn24.pl/pilka-nozna
Are you over 18 and want to see adult content?
Favourite Annotations
![A complete backup of www.malaymail.com/news/malaysia/2020/02/27/2020-stimulus-dr-m-says-epf-rate-cut-to-7pc-rm150-more-cash-hand](https://www.archivebay.com/archive2/514a0cab-8712-4e74-8643-e76d817e2bbc.png)
A complete backup of www.malaymail.com/news/malaysia/2020/02/27/2020-stimulus-dr-m-says-epf-rate-cut-to-7pc-rm150-more-cash-hand
Are you over 18 and want to see adult content?
![A complete backup of topick.hket.com/article/2576268](https://www.archivebay.com/archive2/05c1f780-71e4-493d-93d2-3c1510e5958a.png)
A complete backup of topick.hket.com/article/2576268
Are you over 18 and want to see adult content?
![A complete backup of wiadomosci.wp.pl/patrycja-kotecka-i-gw-gazeta-zarzuca-jej-niebezpieczne-zwiazki-ona-zapowiada-kroki-prawne-](https://www.archivebay.com/archive2/a0c1227f-d09d-4686-aacb-5222fed1f422.png)
A complete backup of wiadomosci.wp.pl/patrycja-kotecka-i-gw-gazeta-zarzuca-jej-niebezpieczne-zwiazki-ona-zapowiada-kroki-prawne-
Are you over 18 and want to see adult content?
![A complete backup of zdrowie.wprost.pl/koronawirus/10301652/msze-odwolane-z-powodu-koronawirusa-terlikowski-kosciol-pokazuje-swo](https://www.archivebay.com/archive2/4514d623-6b98-4701-aaf2-927ccafa42d9.png)
A complete backup of zdrowie.wprost.pl/koronawirus/10301652/msze-odwolane-z-powodu-koronawirusa-terlikowski-kosciol-pokazuje-swo
Are you over 18 and want to see adult content?
Text
like this: >>>
USE DU TO FIND OUT THE DISK USAGE OF EACH DIRECTORY IN So to print out the disk usage summary for a directory go to that directory and run du -h -s *; you need to have access to the child subdirectories so probably it’s better to try this as root (unless you go to your home dir for example). The parameters are -h to print human readable sizes (G, M etc) and -s to print a summary usage ofeach
/VAR/ - GITHUB PAGES A common pattern in Django urls is to have the following setup for CRUD operations of your objects. Let’s suppose we have a Ship object. It’s CRUD urls would be something like: /ships/create/ To add a new object /ships/list/ To display a list of your objects /ships/detail/id/ To display the particular object with that id (primary key) /ships/update/id/ To update/edit the particular object USING MATPLOTLIB TO GENERATE GRAPHS IN DJANGO Nowadays the most common way to generate graphs in your Django apps (or web apps in general) is to pass the data as json to the page and use a javascript lib. QUICK AND EASY LAYOUT OF DJANGO FORMS USING DJANGO-CRISPYCRISPY FORMS LAYOUTHOW TO INSTALL CRISPY FORMS The answer to this is the django-widget-tweaks package: It enables you to easily modify form fields by adding classes, attributes etc to them from within your django templates. To use it you need to add a {% load widget_tweaks %} to your templates. Then you’ll be able to use the |add_class form field to add a class to your form field. DJANGO-RQ REDUX: ADVANCED TECHNIQUES AND TOOLS Introduction. In the previous django-rq article we presented a quick introduction to asynchronous job queues and created a small (but complete) project that used rq and django-rq to implement asynchronous job queues in a django project.. In this article, we will present some more advanced techniques and tools for improving the capabilities of our asynchronous tasks and integrate A COMPREHENSIVE DJANGO CBV GUIDE This class is used as the base in Django’s CBV hierarchy (similar to how CustomClassView was used in our own hierarchy). It has only one attribute ( http_method_names) and a very small number of methods. The most important method is the as_view class method (which is similar to the one we defined in the previous section). USING BOTH PYTHON 2 AND 3 IN WINDOWS The release of Django 2.0 was a milestone in the history of Python since it completely dropped support for Python 2.x. I am a long time user of Django and, loyal to the philosophy of “if it is working don’t change” I was always using Python 2.x. DJANGO DYNAMIC TABLES AND FILTERS FOR SIMILAR MODELS The first method that will be called is the get_queryset method that will generate the dynamic form using define_form.This method has a get_form_field_type local function (similar to get_table_fields) that can be used to override the types of the fields (or just fallback to a normal CharField) and then create the attrs dictionary and forms.Form subclass in a similar way as the Table CREATING CUSTOM COMPONENTS FOR AG-GRID The refresh method generates the text value of the cell (that will be put inside the span we created in init). It first checks if the value attribute of params is defined and if yes, it appends the label of each object attribute (which we pass through cellRendererParams.fields.label) along with its value (which is retrieved from the params.value using cellRendererParams.fields.name). UNDERSTANDING NESTED LIST COMPREHENSION SYNTAX IN PYTHON To write that, somebody would think: For a simple list comprehension I need to write to get all its items - however I want to retrieve each element of the x list so I’ll write somethinglike this: >>>
USE DU TO FIND OUT THE DISK USAGE OF EACH DIRECTORY IN So to print out the disk usage summary for a directory go to that directory and run du -h -s *; you need to have access to the child subdirectories so probably it’s better to try this as root (unless you go to your home dir for example). The parameters are -h to print human readable sizes (G, M etc) and -s to print a summary usage ofeach
/VAR/ - GITHUB PAGES A common pattern in Django urls is to have the following setup for CRUD operations of your objects. Let’s suppose we have a Ship object. It’s CRUD urls would be something like: /ships/create/ To add a new object /ships/list/ To display a list of your objects /ships/detail/id/ To display the particular object with that id (primary key) /ships/update/id/ To update/edit the particular object USING MATPLOTLIB TO GENERATE GRAPHS IN DJANGO Nowadays the most common way to generate graphs in your Django apps (or web apps in general) is to pass the data as json to the page and use a javascript lib. QUICK AND EASY LAYOUT OF DJANGO FORMS USING DJANGO-CRISPY One of the first problems you have when you want to create a traditional HTML django site (i.e not an SPA one) is how to properly and beautifully layout your forms. In this small article I’ll talk about two very useful django packages that will help you have great layouts in your forms: django-crispy-forms and django-widget-tweaks. ADDING A TIMELINE OF YOUR WAGTAIL POSTS Decisions, decisions. For this demo we’ll include all the “blog” pages in the timeline. However we may wanted to select which pages we want to include in the timeline. This could be done either by adding an extra field in our blog pages (class blog.models.BlogPage) like include_in_timeline or by using the Wagtail ModelAdmin functionality. For the ModelAdmin we’d create an extra Django USING HASHIDS TO HIDE IDS OF OBJECTS IN DJANGO Using hashids to hide ids of objects in Django. Πεμ 07 Ιανουάριος 2021. A common pattern in Django urls is to have the following setup for CRUD operations of your objects. Let’s suppose we have a Ship object. It’s CRUD urls would be something like: /ships/create/ To add a new object. /ships/list/ To display a list of your objects. EASY DOWNLOADING YOUTUBE VIDEOS AND MP3S USING YOUTUBE-DL Using youtube-dl. As I’ve already explained before, to run youtube-dl you’ll either write something like py -3-m youtube_dl (if you’ve installed it to your global python packages) or run youtube-dl if you’ve downloaded the pre-built exe or have installed it in a virtualenv. To save you from some keystrokes, you can create a batch file that will run and pass any more parameters to it CREATING CUSTOM COMPONENTS FOR AG-GRID The refresh method generates the text value of the cell (that will be put inside the span we created in init). It first checks if the value attribute of params is defined and if yes, it appends the label of each object attribute (which we pass through cellRendererParams.fields.label) along with its value (which is retrieved from the params.value using cellRendererParams.fields.name). IMPLEMENTING A SIMPLE, HEROKU-HOSTED REST SERVICE USING Introduction. In the following, I will describe how I used Flask, a very nice web microframework for python along with mongoDB, the most popular No-SQL database to implement a simple REST service that was hosted on Heroku.This REST service would get readings from a number of sensors from an Android device.. I chose Flask instead of Django mainly because the REST service EASY IMMUTABLE OBJECTS IN JAVASCRIPT The order is similar to Object.assign, i.e the attributes that follow will override the previous ones. One final comment is that both Object.assign and copying objects with the spread syntax will do a “shallow” copy i.e it will copy only the outer object, not the objects its keys refer to. An example of this behavior is that if yourun the following:
RETRIEVING GMAIL BLOCKED ATTACHMENTS Save this to a file named get_attachments.py and, after saving the original message to a file named 0.txt run python get_attachments.py 0.txt and you’ll see the attachments of your email in the same folder!. Disclaimer: I have to warn you that since Gmail claims that an attachment is not safe it may be actually not safe.So you must be 100% sure that you know what you are doing before/VAR/
VARIOUS PROGRAMMING STUFF* Android
* Css
* Django
* Elixir
* Flask
* Git
* Html
* Javascript
* Pelican
* Postgresql
* Python
* Spring
* Unix
* Wagtail
Hello! I see that you have an ad blocker. If you find something useful here and want to support me somehow please consider disabling your ad blocker for this site. It won't cost you anything. DECLARATIVE ECTO QUERY SORTING Πεμ 17 Οκτώβριος 2019 In a previous article I presented a method for declaring dynamic filters for your ecto queries. Continuing this article, I’ll present here a way to allow dynamic sorting for your queries using fields that may evenspan relations.
WHAT WILL IT DO
The solution is a couple of function that can be put inside the QueryFilterEx I mentioned in the previous article.
Please make sure that you’ve completely read and understand this article before continuing here. To use the dynamic sorting function you’ll need to declare the fields that would allow sorting using a simple array of strings. The sort fields should then be added as links to your phoenix page which will then pass an order_by=field_name query parameter toyour controller.
The module has a very simple API consisting of a single function: * sort_by_params(query, params, allowed_sort_fields): Pass it the query, the GET request parameters you got from your form and the declared sort fields array to return you a sorted query You can find a sample of the technique presented in this article in my PHXCRD repository: https://github.com/spapas/phxcrd for example in the user_controller or authority_controller. PREPARING THE QUERY In order to use dynamic sorting you’ll need to properly “prepare” your Ecto query by _naming all your relations_ as I’ve already explained in the previous article.
DECLARING THE SORT FIELDS To declare the sort fields you’ll just add an array of fields you’ll want to allow sorting on. Each field should have the form binding_name__field_name where binding_name is the name of the table you’ve declared in your query and field_name is the name of the field that the query will be sorted by. This is the way that the sort fields will also be declared in the phoenix html page. Django users will definitely remember the model__field convention. Declaring the sort fields here and using them again in the html page may seem reduntant, however it is absolute necessary to declare a priori which fields are allowed because the sort http params will be received as strings and to be used in queries these strings will be converted to atoms. The number of atoms is finite (there’s an absolute limit of allowed atoms in an erlang program; if that limit is surpassed your program will crash) so you can’t allow the user to pass whatever he wants (so if the order_by parameter does not contain one of the fields you declare here then no strings will be convertedto atoms).
INTEGRATING WITH A CONTROLLER As an example let’s see how the dynamic sort fields will be integrated with the phxcrd user_controller. The query I’d like to filter on is the following (see that everything I’ll need is namedusing :as):
from(u in User, as: :user, left_join: a in Authority, as: :authority, on: a.id == u.authority_id, left_join: up in UserPermission, on: up.user_id == u.id, left_join: p in Permission, as: :permission, on: up.permission_id == p.id,preload:
)
To declare the sort fields I like to create a module attribute ending with sort_fields, something like @user_sort_fields for example. Here’s the sort fields I’m going to use for user_controller:@user_sort_fields
So it will only allow the user.username, user.name and user.last_login fields for sorting. I could easily sort by authority.name or permission.name in a similar fashion. Finally, here’s the full code of the index controller: def index(conn, params) do changeset = QueryFilterEx.get_changeset_from_params(params, @user_filters)users =
from(u in User,
as: :user,
left_join: a in Authority, as: :authority, on: a.id == u.authority_id, left_join: up in UserPermission, on: up.user_id == u.id, left_join: p in Permission, as: :permission, on: up.permission_id == p.id,preload:
)
|> QueryFilterEx.filter(changeset, @user_filters) |> QueryFilterEx.sort_by_params(params, @user_sort_fields)|> Repo.all()
render(conn, "index.html", users: users, changeset: changeset)end
Notice that this is exactly the same as the controller I discussed in the dynamic filters article with the addition of the QueryFilterEx.sort_by_params(params, @user_sort_fields) pipe to dothe sorting.
THE TEMPLATE
The template for the user index action is also the same with a couple of minor changes: Instead of using a static header for the table title I will use a link that will change the sorting order:<%= link gettext("Username"), to: create_order_url(@conn, "user__username") %>
<%= link gettext("Name"), to: create_order_url(@conn, "user__name") %>
First name Last name
Email
Am / Am phxcrd Kind
<%= link gettext("Last login"), to: create_order_url(@conn, "user__last_login") %>
Is enabled
Notice that I just used the create_order_url function passing it the @conn and the sort field. This create_order_url function is implemented in a module I include in all my views and will properly add an order_by=field in the url (it will also add an order_by=-field if the same header is clicked twice). I will explain it more in the following sections. Finally, please notice that if you use pagination and sorting you need to properly handle the order_by query parameter when creating the next-previous page links. Actually, there are three things competing on their url parameter dominance; I’d like to talk about that in the <%= link gettext("Username"), to: create_order_url(@conn, "user__username") %>
<%= link gettext("Name"), to: create_order_url(@conn, "user__name") %>
Last name
Email
Kind
<%= link gettext("Last login"), to: create_order_url(@conn, "user__last_login") %>
next interlude.
INTERLUDE: HTTP GET PARAMETER PRIORITY Now, in an index page you will probably have three things all of which will want to put parameters to your urls to be activated: * Query filtering; this will put a filter query parameter to filter your query. Notice that because of how phoenix works (it allows maps in the query parameters) the filter can be a single query parameter but contain multiple filters (i.e the filter will be something like %{"key1" => "value1", "key2" => "value2"} * Order by: This will put an order_by query parameter to denote the field that the query will be sorted * Pagination: This will put an page query parameter to denote thecurrent page
I like to give them a priority in the order I’ve listed them; when one of them is changed, it will _clear_ the ones following it. So if the query filters are changed both the pagination and the order by fields will be cleared, if the order by field is changed then only the pagination field will be cleared but if the pagination field is changed both the query filters and the order by fields will bekept there.
I think that’s the best way to do it from an UX point of view; try to think about it and you’ll probably agree. HOW DOES THIS WORK? In this section I’ll try to explain exactly how the dynamic sortfields work.
So I’ll split this explanation in two parts: Explain create_order_url and then explain sort_by_params.CREATE_ORDER_URL
This function receives three parameters: The current @conn, the name of a field to sort by and an optional list of query parameters that need to be kept while creating the order by links. I’ve put this function in a ViewHelpers module that I am including to all my views (by adding an import PhxcrdWeb.ViewHelpers line to the PhxcrdWebmodule).
Let’s take a look at the code: def create_order_url(conn, field_name, allowed_keys \\ ) do Phoenix.Controller.current_url(conn, get_order_params(conn.params, allowed_keys, field_name))end
This doesn’t do much, it just uses the phoenix’s current_url that generates a new url to the current page, passing it a dictionary of http get parameters that should be appended to the url that are created through get_order_params. Notice that there’s an allowed_keys parameter that contains the query parameters that we need to keep after the sorting (see the previous interlude). By default I pass the filter query parameter so if theres a filter (check my previous article) it will keep it when sorting (but any pagination will be cleared; if I sort by a new field I want to go to the first page there’s no reason for me to keep seeing the page I was on before changing the order by). The get_order_params receives the query parameters of the current connection (as a map), the allowed keys I mentioned before and the actual name of the field to sort on. This method is a littlemore complex:
defp get_order_params(params, allowed_keys, order_key) doparams
|> Map.take(allowed_keys ++ ) |> Enum.map(fn {k, v} -> {String.to_atom(k), v} end)|> Map.new()
|> Map.update(
:order_by,
order_key,
&case &1 do
"-" <> ^order_key -> order_key ^order_key -> "-" <> order_key _ -> "-" <> order_keyend
)
end
It only keeps the parameters in the allowed_keys list and the current order_by parameter (if there’s one) discarding everything else. It will then convert the keys of the map to atoms and put them in a new map. Finally, it will update the order_by field (if exists) either by switching the - in front of the field to declare asc/desc sorting or adding it for the field that was clicked. Actually the logic of that Map.update is the following: * If there’s no :order_by key then add it and assign the passedorder_key
* If the current value of :order_by is equal to order_key with or without a - then toggle the - (this happens when you click on a field that is already used for sorting) * If the current value of :order_by is anything else (i.e not the same as the order_key) then just change :order_by to -orderKey (this happens when there’s sorting but you click on a different field, not the one used for the sorting) Notice that this juggling between map, list of keywords and then map again (using Enum.map and then Map.new etc) is needed because the query parameters are in a map with strings as keys form (%{"key" => "value"}) while the current_url function needs the query params in a map with atoms as keys form (%{key: "value"}).SORT_BY_PARAMS
The sort_by_params method gets three parameters: The query that will be sorted, the existing http parameters map (so as to retrieve the order_by value) and the declared list of allowed sorting fields. Let’s take a look at it: def sort_by_params(qs, %{"order_by" => "-" <> val}, allowed), do: do_sort_by_params(qs, val, :asc, allowed) def sort_by_params(qs, %{"order_by" => val}, allowed), do: do_sort_by_params(qs, val, :desc, allowed) def sort_by_params(qs, _, _), do: qs This multi-legged function will only do something if there’s an order_by parameter in the http parameters (else it will just return the query as is) and will call do_sort_by_params passing it the received query, either :asc or :desc (depending if there’s a - in front of the value) and the received allowed fields list. The do_sort_by_params makes sure that the passed parameter is in the allowed list and if yes it creates the atoms of the binding and field name (using String.to_atom) and does the actual sorting to thepassed query:
defp do_sort_by_params(qs, val, ord, allowed) do if val in allowed do = val |> String.split("__") |> Enum.map(&String.to_atom/1) qs |> order_by(, )else
qs
end
end
The line qs |> order_by(, ) may seem a little complex but it has been thoroughly explained in theprevious article.
CONCLUSION
By using the methods described here you can easily add a dynamic sorting to your queries through fields that may span relations just by creating a bunch of http GET links and passing them an order_byquery parameter.
HOW TO PROPERLY HANDLE AN HTML FORM Πεμ 03 Οκτώβριος 2019 One of the simplest things somebody would like to do in a web application is to display a form to the user and then handle the data the application received from the form. This is a very common task however there are many loose ends and things that a new developer can do wrong. Recently, I tried to explain this to somebody however I couldn’t find a tutorial containing all the information I think it is important. So I decided to write it here. To make it very easy to test it and understand it I decided to use PHP to handle the form submission. I must confess that I don’t like PHP and I never use it in production apps (unless I need to support an existing one). However, for such simple tasks and examples PHP is probably the easiest thing for a new developer to understand: Just create a .php file and put it in a folder in your apache htdocs; there now you can test the behavior! This tutorial will be as comprehensive as possible and will try to explain all things that I feel that need explaining. However I won’t go into details about HTML or PHP syntax; you’ll need to know some things about them to understand what’s going on here; after all the important thing is to understand the big picture so you can re-implement them in your case (or understand why your web framework does what it does). A QUICK HTTP PRIMER So, what happens during a form display and submission? To properly understand that you need to know what an HTTP request is. An HTTP request is the way the browser “requests” a URL from a web server. This is thoroughly explained in the HTTP protocol however, for our purposes here it should suffice to say that an HTTP request is a text message that is send from the browser/HTTP Client to the HTTP/web server. This message should have the following format: METHOD PATH HTTP/VERSION Header 1: Value 1 Header 2: Value 2Request data
The METHOD can be one of various methods supported in the HTTP protocol like GET, POST, PUT, OPTIONS etc however the most popular and the ones we’ll talk about here are GET and POST. The PATH is the actual url of the “page” you want to view without the server part. So if you are visiting http://www.example.com/path/to/page.html the path parameter will have a value of /path/to/page.html. The HTTP/VERSION will contain the version of HTTP the client uses; usually it is something like HTTP/1.1. Finally, after that first line there’s a bunch of optional headers with various extra information the client wants to pass to the server (for example what encoding it supports, what’s the host it connects to etc). Additionally, in case of a POST request the headers are followed by a blank line which in turn is followed by a chunk of “data” that the client passes to the server. The server will then response back with a text message similar to this(HTTP Response):
HTTP/VERSION STATUS Header 1: Value 1 Header 2: Value 2Response data
The HTTP/VERSION will also be something like HTTP/1.1 while the STATUS will be the status of the response. This status is a 3-digit numeric value followed by a textual description of the status. There are various statuses that you can receive , however the statuses can be grouped by the number they start withlike this:
* 1xx: Information; rarely used * 2xx: Success; status 200 is the most common one * 3xx: Redirection (browser must visit another page); either permanent or temporary * 4xx: Client error; 404 is page not found (also access denied errors will be 40x) * 5xx: Server error; something fishy happened to the serverwhile responding
In this article we’ll mainly talk about 2xx and 3xx: A 200 OK answer is the most common one, it means that the HTTP request was completed successfully. A 302 FOUND request means that the browser should display a “different” path; that path will be provided in a Location: path header. When the browser receives a redirect it will do another GET request to retrieve the redirect to page. Notice that the Headers and Data parts of the server reply may also be optional like for the client however they usually exist (especially with a 200 response; without the data the client won’t have anythingto display).
So when a browser “requests” a page it will send an HTTP GET to the path. This happens all the time when we visit(click) links or entering urls to our browser. However, when we submit an HTML form the situation is a little more complex.FORM METHODS
An html form is a So what are the differences between aDetails
Copyright © 2024 ArchiveBay.com. All rights reserved. Terms of Use | Privacy Policy | DMCA | 2021 | Feedback | Advertising | RSS 2.0