Skip to content

Instantly share code, notes, and snippets.

View taai's full-sized avatar

Jānis Lācis taai

  • Latvia
View GitHub Profile
@taai
taai / fix-constructors.php
Created October 5, 2022 11:39
Rename class constructor methods to `__construct`
<?php
// dry run
// find . -type f -name '*.php' -exec php fix-constructors.php {} \;
// real run
// find . -type f -name '*.php' -exec php fix-constructors.php {} y \;
// @read https://ideone.com/aLpfBh
// @read https://regex101.com/r/hzzzkz/1/
@taai
taai / TcpClientExtensions.cs
Created February 17, 2022 22:07
TcpClient extensions
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
namespace Extensions.Tcp
{
public static class TcpClientExtensions
{
@taai
taai / example.js
Created February 15, 2021 09:03
JavaScript AbortController example for custom async function
function getUserById(userId, signal) {
if (signal.aborted) {
return Promise.reject(new DOMException('The API request was aborted.', 'AbortError'));
}
return new Promise(function(resolve, reject) {
const jobTimeout = setTimeout(function() {
signal.removeEventListener('abort', abortHandler);
resolve({ id: userId, name: 'John' });
}, 3000);
@taai
taai / test.js
Last active February 14, 2021 17:14
JavaScript AbortController example
const url = 'big.mkv';
const abortController = new AbortController();
setTimeout(function() {
abortController.abort();
}, 1);
async function fetchVideo() {
try {
const response = await fetch(url, { signal: abortController.signal });
@taai
taai / convert_number_to_latvian_words.php
Created August 13, 2019 14:58
Convert number to Latvian words
<?php
function convert_number_to_latvian_words($num)
{
if ( ! is_numeric($num))
return false;
if (($num >= 0 && (int) $num < 0) OR (int) $num < 0 - PHP_INT_MAX) {
// overflow
trigger_error('convert_number_to_latvian_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX, E_USER_WARNING);
@taai
taai / gist:7747966
Last active December 30, 2015 00:09
This enables IE9 to do a CORS (cross-domain) request. Place this right after jQuery script. I recommend to download this and save it locally. Library can found here: https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest
<!--[if IE 9]>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.1/jquery.xdomainrequest.min.js"></script>
<![endif]-->
@taai
taai / vestule
Created August 9, 2013 09:44
Vēstule Latvijas Republikas Saeimai. Rīgā, 2013. gada 9. augustā.
Sveicināti!
Vēlos izteikt pretenziju par grozījumiem Latvijas Administratīvo pārkāpumu kodeksā - Nr: 431/Lp11.
Pretenzijas man ir pret 171.3 pantu.
171.3 pants. Alkoholisko dzērienu iegādāšanās, ja pircējs vecumā no 18 līdz 25 gadam neuzrāda personu apliecinošu dokumentu
Par alkoholisko dzērienu iegādāšanos, ja pircējs vecumā no 18 līdz 25 gadam neuzrāda personu apliecinošu dokumentu –izsaka brīdinājumu vai uzliek naudas sodu līdz divdesmit pieciem latiem.
Loģiski spriežot, 24 gadus veca persona, iegādājoties alkoholiksu dzērienu un neuzrādot personu apliecinošu dokumentu, būs izdarījusi administratīvu pārkāpumu, par kuru var tikt sodīta ar līdz pat 25 latu naudas sodu.
@taai
taai / example.html
Last active December 17, 2015 04:18
<script>
Post = can.Model({
}, {
init: function() {
var children = this.children;
this.removeAttr('children');
this.children = new Post.List( children.serialize() );
}
});
@taai
taai / gist:4155288
Created November 27, 2012 16:33
Classes loaded
I18n
Kohana_I18n
Log
Kohana_Log
Config
Kohana_Config
App_Exception_Handler
Log_File
Kohana_Log_File
Log_Writer
@taai
taai / Handler.php
Created November 27, 2012 16:19
Can't set custom exception handler in Kohana 3.3
<?php defined('SYSPATH') or die('No direct script access.');
/**
* App Exception handler
*/
class App_Exception_Handler {
public static function handle(Exception $e)
{