Skip to content

Instantly share code, notes, and snippets.

View rcknr's full-sized avatar

Sergii Kauk rcknr

View GitHub Profile
@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 / 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 / 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 +
@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 / 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 / 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 / README.md
Last active May 4, 2016 20:21 — forked from kaezarrex/README.md
GTFS Viewer

Upload a GTFS file that contains shapes.txt. Example GTFS files can be found at the GTFS Data Exchange.

@rcknr
rcknr / README.md
Last active July 19, 2018 12:36
Using Let's Encrypt certificates with Amazon API Gateway

##Using Let's Encrypt certificates with AWS API Gateway

Before starting off with API Gateway set up it's worth mentioning that certificate configuration for this particular service is so far isn't well integrated, therefore different from other AWS services. Despite it using CloudFrount to serve on custom domains it won't let you customize distributions it creates, however all the limitations of CloudFront naturally apply to API Gateway. The most important in this case is the size of the key, which is limited by 2048 bit. Many tutorials provide ready to use terminal commands that have the key size preset at 4096 bit for the sake of better security. This won't work with API Gateway and you'll get an error message about certificate's validity or incorrect chain which won't suggest you the real cause of the issue. Another consideration is that to add a custom domain to API Gateway you have to have a certif

@rcknr
rcknr / csv2array.php
Created October 2, 2015 22:55
Convert a CSV file to an associative array
<?php
$source = file('http://example.com/example.csv');
$csv_array = array_map('str_getcsv', $source, array_fill(0, count($source), ';'));
$header = array_shift($csv_array);
$result = array_map('array_combine', array_fill(0, count($csv_array), $header), $csv_array);
?>
@rcknr
rcknr / Code injection
Last active October 19, 2015 19:04
UI translation (i18n) for Squarespace
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.min.js"></script>
<script>
Y.use('node', 'node-load', function(Y) {
Y.on('domready', function() {
/* Locale to use with moments.js */
var locale = 'de_AT';
/* Format blog entries published dates */
Y.all('time.published').each(
function() {