Skip to content

Instantly share code, notes, and snippets.

View KarelWintersky's full-sized avatar

Karel Wintersky KarelWintersky

View GitHub Profile
@samarpanda
samarpanda / gist:4125105
Last active December 1, 2023 08:20
Test your php code execution time and Memory usage
<?php
// from http://php.net/manual/en/function.filesize.php
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
// by Erik Wrenholt
import java.util.*;
class Mandelbrot
{
static int BAILOUT = 16;
static int MAX_ITERATIONS = 1000;
private static int iterate(float x, float y)
{
@CrocoDillon
CrocoDillon / _blank.js
Last active August 30, 2023 21:27
Automatically open external links in new tab or window.
// vanilla JavaScript
var links = document.links;
for (var i = 0, linksLength = links.length; i < linksLength; i++) {
if (links[i].hostname != window.location.hostname) {
links[i].target = '_blank';
}
}
// or in jQuery
@nrk
nrk / fizzbuzz_generators.php
Last active July 16, 2023 16:37
FizzBuzz'ing in PHP, just for the heck of it.
<?php
// Same approach as of `fizzbuzz_short.php` but with some generators love so you
// can fizzbuzz all you want without blowing up you memory. HOW GREAT IS IT?
$fbrange = function ($start, $stop) {
if ($start > 0) {
for ($n = $start; $n < $stop; $n++) {
yield (($f=!($n%3))|($b=!($n%5)))?($f?'Fizz':'').($b?'Buzz':''):"$n";
}
modifier: None
created:
modified: 20100127161718
type: None
tags: systemConfig
/***
|Name|BookmarkletPlugin|
|Version|0.1|
|Author|Ben Gillies|
@ttscoff
ttscoff / logr.bash
Last active April 16, 2022 23:59
Bash logging utility that simplifies use of logger command
#!/bin/bash
# Logging utility that simplifies user of bash logger command
# # First source the script
# source ~/scripts/logr.bash
# # Start the logger, generates log name from scripts filename
# logr start
# # or define your own
# logr start LOG_NAME
@fomigo
fomigo / gist:2382775
Created April 14, 2012 07:59
Russian Plural Form in PHP
<?php
/*
echo plural_form(42, array('арбуз', 'арбуза', 'арбузов'));
*/
function plural_form($n, $forms) {
return $n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]);
}
@richardwellerson
richardwellerson / goAccessGuide.md
Last active September 21, 2021 21:09
GoAccess Installation

GoAccess Guide Install

I've tried so much times install GoAccess. For this reason, i create this gist to make your job easy.

Don't skip the steps:

Install GeoIP Lib

$ sudo su
# cd /usr/local/src
@KarelWintersky
KarelWintersky / mysql_dbu_create.sh
Created October 2, 2020 13:53
MySQL -- create user & database + password
#!/usr/bin/env bash
#
# Script to create MySQL db + user
#
# @author Karel Wintersky <karel.wintersky@gmail.com>
# @version 0.2
# mysql_config_editor set --login-path=proftpd --host=localhost --user=proftpd --password
@krypt-lynx
krypt-lynx / jff-csv.cs
Last active July 25, 2020 21:31
Comma Separated Values reader/writer
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace csv
{
static class CSV
{