Skip to content

Instantly share code, notes, and snippets.

@ksdev-pl
ksdev-pl / naturalOrderBy.js
Last active December 2, 2022 11:03
Natural sort orderBy filter for vue.js #js
naturalSort.insensitive = true;
Vue.filter('naturalOrderBy', function (arr, sortKey, reverse) {
if (!sortKey) {
return arr;
}
var order = (reverse && reverse < 0) ? -1 : 1;
return arr.slice().sort(naturalSort.bind(null, sortKey, order));
});
@ksdev-pl
ksdev-pl / write_append.md
Last active August 29, 2015 14:14
Write / append some text to a file #serwer

If you want to write some text to a file that needs a root privileges, you do it this way:

echo "Text I want to write" | sudo tee /path/to/file > /dev/null

or:

sudo sh -c 'echo "Text I want to write" > /path/to/file'

If you just want to append some text, you do it this way:

@ksdev-pl
ksdev-pl / this.md
Last active August 29, 2015 14:12
"This" in JavaScript #js
  1. The keyword "this" refers to whatever is left of the dot at call-time.
  2. If there's nothing to the left of the dot, then "this" is the root scope (e.g. Window).
  3. A few functions change the behavior of "this"—bind, call and apply
  4. The keyword "new" binds this to the object just created

So if you're using the value of "this" in someFunction...

thing.someFunction(); // this === thing
someFunction();       // this === Window
new someFunction(); // this === the newly created object
@ksdev-pl
ksdev-pl / find_and_remove.md
Created November 30, 2014 17:48
Znajdź i usuń plik #serwer

To remove multiple files such as *.jpg or *.sh with one command find, use:

find . -name "FILE-TO-FIND" -exec rm -rf {} \;

OR

find . -type f -name "FILE-TO-FIND" -exec rm -f {} \;

The only difference between above two syntax is that the first command remove directories as well where second command only removes files. Options:

@ksdev-pl
ksdev-pl / polling.md
Last active October 15, 2020 07:26
Polling (setInterval, setTimeout) #js

The setInterval Technique

Now, if you needed to poll your web service, your first instinct might be to do something like this with JavaScript and jQuery:

setInterval(function(){
    $.ajax({ url: "server", success: function(data){
        //Update your dashboard gauge
        salesGauge.setValue(data.value);
 }, dataType: "json"});
------------------------------------------------------------
C:\Program Files (x86)\JetBrains\PyCharm Community Edition 3.1.2\helpers\packaging_tool.py run on 07/24/14 19:34:45
DEPRECATION: --no-install, --no-download, --build, and --no-clean are deprecated. See https://github.com/pypa/pip/issues/906.
Downloading/unpacking pelican
Getting page https://pypi.python.org/simple/pelican/
URLs to search for versions for pelican:
* https://pypi.python.org/simple/pelican/
Analyzing links from page https://pypi.python.org/simple/pelican/
Found link https://pypi.python.org/packages/2.7/p/pelican/pelican-3.4.0-py2.py3-none-any.whl#md5=b6246f58cd02dfba752bb5c9b4534b13 (from https://pypi.python.org/simple/pelican/), version: 3.4.0
Found link https://pypi.python.org/packages/source/p/pelican/pelican-1.1.1.tar.gz#md5=721e60eedcb2bced8bea1e5780c9eaaa (from https://pypi.python.org/simple/pelican/), version: 1.1.1
@ksdev-pl
ksdev-pl / remove_older_than.md
Last active November 28, 2015 16:17
Usuń pliki i foldery starsze niż #serwer
find /home/protected/app/storage/backups/* -type d -not -newerct '30 minutes ago' -print0 | xargs -r rm -rf
find /var/www/gistlist.ksdev.pl/app/storage/backups/* -type d -mmin +30 -exec rm -rf {} +
@ksdev-pl
ksdev-pl / auth.md
Last active August 29, 2015 14:01
Identyfikacja, uwierzytelnianie i autoryzacja #metodyka

Identyfikacja (identification)

Podmiot deklaruje swoją tożsamość (identity). Na przykład:

  • w rozmowie telefonicznej z centrum obsługi banku klient deklaruje swoje imię, nazwisko i numer konta (bank jest stroną ufającą);
  • w procesie logowania do serwera użytkownik wpisuje nazwę (login) (serwer jest stroną ufającą);
  • podczas połączenia przeglądarki z serwerem SSL, ten ostatni przedstawia certyfikat X.509 zawierający jego nazwę (przeglądarka jest stroną ufającą).

Uwierzytelnianie (authentication)

Strona ufająca stosuje odpowiednią technikę uwierzytelniania (authentication mechanism) w celu weryfikacji zadeklarowanej wcześniej tożsamości. Na przykład:

@ksdev-pl
ksdev-pl / restful_routes.md
Last active August 29, 2015 14:01
RESTful routes #metodyka
Verb Path Action Route Name
GET /resource index resource.index
GET /resource/create create resource.create
POST /resource store resource.store
GET /resource/{resource} show resource.show
GET /resource/{resource}/edit edit resource.edit
PUT/PATCH /resource/{resource} update resource.update
DELETE /resource/{resource} destroy resource.destroy