Skip to content

Instantly share code, notes, and snippets.

View KarelWintersky's full-sized avatar

Karel Wintersky KarelWintersky

View GitHub Profile
// 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)
{
@silverslice
silverslice / DbMysql.php
Last active August 29, 2015 14:14
Mysql wrapper for legacy projects
<?php
/**
* Подключение к БД
*
* @param $host
* @param $user
* @param $pass
* @param $db
* @return bool|resource
*/
@ozee31
ozee31 / in_array.js
Created August 7, 2014 14:46
Indique si une valeur appartient à un tableau
/**
* Checks if a value exists in an array
* @param {mixed} needle : The searched value
* @param {array} haystack : The array
* @return {bool}
*/
var in_array = (function (needle, haystack) {
return ( haystack.indexOf(needle) !== -1 );
});
@ozee31
ozee31 / array_unset.js
Last active June 18, 2020 11:20
Supprime des éléments d'un tableau
/**
* Remove all occurrences of a given value from an array
* @param {mixed} val : value to delete
*/
Array.prototype.unset = function(val){
var index;
while ( (index = this.indexOf(val)) !== -1 ) {
this.splice(index,1);
}
@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
{
@prwhite
prwhite / Makefile
Last active April 4, 2024 19:01
Add a help target to a Makefile that will allow all targets to be self documenting
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
# Everything below is an example
target00: ## This message will show up when typing 'make help'
@echo does nothing
@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";
}
@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);
@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]);
}