Skip to content

Instantly share code, notes, and snippets.

View rcknr's full-sized avatar

Sergii Kauk rcknr

View GitHub Profile
@rcknr
rcknr / README.md
Created August 28, 2018 07:37
Laravel Custom Hasher

Laravel Custom Hasher

When you need to hash and check passwords using an algorithm other than supported bcrypt or argon there is an easy way to add a custom one. When I needed to use md5 for a legacy project I have tried to quickly google a solution and most I had found were based on creating a ServiceProvider which completely overrides builtin HashManager. The other way would be to extend it instead. So I have added a following into my AuthServiceProvider's boot() method:

$this->app->make('hash')->extend('md5', function() {
    return new Md5Hasher;
});
@rcknr
rcknr / add2books.html
Created May 30, 2013 08:27
Add PDF and EPUB files from your Google Drive to Google Books.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Add to Google Books</title>
<script src="//www.google.com/jsapi"></script>
<script src="//apis.google.com/js/client.js"></script>
<script type="text/javascript">
@rcknr
rcknr / Code.gs
Last active March 13, 2024 21:49
MD5 Hash in Google Apps Script
function md5(inputString) {
return Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, inputString)
.reduce((output, byte) => output + (byte & 255).toString(16).padStart(2, '0'), '');
}
@rcknr
rcknr / DriveUpload.gs
Last active February 15, 2023 20:06
This is a sample code to upload a PDF file to Google Drive with OCR in Apps Script. uploadPdfOcr function returns a File object. To run the code provide a developer key for an API Console project with Drive API service enabled.
function uploadPdfOcr() {
authorize();
var key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // <-- developer key
var file = UrlFetchApp.fetch("http://somewhere.com/path/file.pdf").getBlob();
var metadata = { title: file.getName() }
var params = {method:"post",
oAuthServiceName: "drive",
oAuthUseToken: "always",
contentType: "application/pdf",
contentLength: file.getBytes().length,
@rcknr
rcknr / 1-README.md
Last active July 20, 2022 17:39
GroupByPagination Trait - Laravel Eloquent Custom Pagination Example

GroupByPagination Trait

An example of custom pagination for Laravel Eloquent. In this scenario we have a model with a column (e.g. date) which we want to use to group records with for pagination but at the same time we still want to work with separate entities in the view.

The trait replaces QueryBuilder with a custom class which overrides forPage method used for pagination. It normally adds OFFSET and LIMIT parameters to the query which limit the number of results for a particular page. In our case though we are quering the datasource first for values of the defined groups and getting the minimum and maximum values to use them in the pagination query instead of LIMIT and OFFSET. We are also removing defined groups for the final query, so the pagination will use grouped dataset while results will be individual records.

After setting up the trait in a model you simply call paginate(). If no groups are defined the original forPage() method will be used instead.

Example:

@rcknr
rcknr / Code.gs
Last active February 12, 2021 21:19 — forked from anonymous/gist:4169590
Get Google Spreadsheet as PDF with customizations
function spreadsheetToPDF(key) {
var spreadsheet = SpreadsheetApp.openById(key);
var response = UrlFetchApp.fetch(spreadsheet.getUrl() + '/export?exportFormat=pdf&gid=1&gridlines=0&printtitle=0&size=7&fzr=true&portrait=1&fitw=1', {
muteHttpExceptions: true,
headers: {
Authorization: 'Bearer ' + ScriptApp.getOAuthToken(),
}
});
@rcknr
rcknr / urlencode.sh
Created January 8, 2013 21:39
Simplistic URL encoding for Busybox shell.
#!/bin/sh
echo "$@" | awk -v ORS="" '{ gsub(/./,"&\n") ; print }' | while read l;
do
case "$l" in
[-_.~a-zA-Z0-9] ) echo -n ${l} ;;
"" ) echo -n %20 ;;
* ) printf '%%%02X' "'$l"
esac
done
@rcknr
rcknr / DriveCommenter.gs
Created December 24, 2012 13:59
An example of using Drive API v2 in Apps Script. This will add "commenter" permission to a specified file. Note that not all types of documents support this permission type. To use this you need to create a project in API Console, enable Drive API in Services and get the API key.
function fileAddCommenter() {
authorize();
var fileId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // <-- id of the document
var key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // <-- developer key
var requestBody = {
role: "reader",
type: "user",
value: "someone@somewhere.com",
additionalRoles: ["commenter"]
};
@rcknr
rcknr / Notes.md
Last active December 7, 2018 19:43
Some information about Denon/Marantz network players

Models

Denon:

  • DRA-N5 - 1. Generation Ceol Piccolo
  • DRA-N4 - 2. Generation Ceol Piccolo
  • DRA-N8 - 1. Generation with CD and FM
  • DRA-N9 - 2. Generation with CD and FM
  • RCD-N10 - 3. Generation with CD and FM

Marantz

  • M-CR510, M-CR511 (marketed as Melody Stream) ** SN: 35001528000591
@rcknr
rcknr / at_vat.php
Last active September 26, 2018 20:55
Austrian VAT Number Validation
<?php
$test = 'ATU10223006';
$check_array = array_chunk(
str_split(substr($test, 3, -1)),
2
);
$checksum = (10 - (4 +