Skip to content

Instantly share code, notes, and snippets.

@bondarewicz
bondarewicz / gist:8041275
Last active December 2, 2019 20:01
JS: estimated reading time
var read_time = function(text){
var minutes = Math.floor(text.split(' ').length / 200 )
if(minutes === 0) minutes = 1
return minutes + ' min read'
}
@bondarewicz
bondarewicz / gist:7706371
Last active December 29, 2015 17:49
Red, anyone?
<font color="red">Red, anyone?</font>
<font color=”red”>Red, anyone?</font>
@bondarewicz
bondarewicz / gist:7690874
Created November 28, 2013 12:08
JS: Confirm leaving page
window.onbeforeunload = function() {
return 'You will lose all changes if you leave this page.';
};
@bondarewicz
bondarewicz / gist:7101128
Last active April 13, 2018 17:01
PHP: Google GeoCoding Example
<?php
$input = "1600 Amphitheatre Parkway, Mountain View, CA";
$request = array();
$request['url'] = "http://maps.googleapis.com/maps/api/geocode/json?address=";
$request['address'] = urlencode($input);
$request['sensor'] = "&sensor=true";
print "<pre>"; print @file_get_contents(join('',$request));
@bondarewicz
bondarewicz / gist:6932069
Created October 11, 2013 09:30
JS: widget.js
(function() {
// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src",
@bondarewicz
bondarewicz / gist:6899641
Last active December 25, 2015 01:59
PHP: Estimated reading time
<?php
function read_time($text){
$words = str_word_count(strip_tags($text));
$min = floor($words / 200);
if($min === 0) return '1 min read';
return $min . 'min read';
}
@bondarewicz
bondarewicz / gist:6672092
Last active December 23, 2015 17:59
PHP: Google Currency
<?php
$result = @file_get_contents("http://www.google.com/ig/calculator?hl=en&q=100GBP=?PLN");
var_dump($result);
@bondarewicz
bondarewicz / gist:6594346
Created September 17, 2013 13:34
PHP: Prime Numbers
<?php
$primes = array();
for ($i = 0; $i <= 1000; $i++) {
if(isPrime($i) === true) array_push($primes, $i);
}
<?php
function pretty($elem, $class, $func_name) {
echo '<'. $elem.' class="' . $class . '">';
call_user_func($func_name);
echo '</'.$elem.'>';
}
function main_page() {
@bondarewicz
bondarewicz / gist:5310944
Last active December 15, 2015 19:19
JS: Returns a random number between min and max
/**
* Returns a random number between min and max
* @param min in range [default 1]
* @param max in range [default 100]
* @dec decimal places for result [default 2]
*
* @return float
*/
function getRandomArbitary (min, max, dec) {