Skip to content

Instantly share code, notes, and snippets.

View rustedwolf's full-sized avatar

Ryszard Narkiewicz rustedwolf

  • TheStory
  • Wołczuny, Lithuania
View GitHub Profile
@rustedwolf
rustedwolf / strToSeconds
Created June 19, 2017 10:55
Simple time string convertion to seconds with miliseconds included
function strToSeconds(timeStr) {
const strParts = timeStr.split(':').reverse();
let time = parseFloat(strParts[0]);
time += parseInt(strParts[1]) * 60;
if (!!strParts[2])
time += parseInt(strParts[2]) * 3600;
return time;
}
@rustedwolf
rustedwolf / parse-location-search.js
Last active February 20, 2017 22:54
Parses location.search string in ES2015
/*
* A method by @tmetler done in ES2015
* Original method source http://www.timetler.com/2013/11/14/location-search-split-one-liner/
*/
/**
* Parses location.search string
* @return {Obeject} Search parameters
*/
function parseSearch() {
@rustedwolf
rustedwolf / sum_divisors.rs
Created November 20, 2016 14:17
Sums all number divisors
fn sum_divisors(number: u32) -> u32 {
let mut sum = 0;
let limit = if number % 2 == 0 { number / 2 } else { number / 3 }; // speeds up the process
for divisor in 1..limit + 1 {
if number % divisor == 0 {
sum += divisor;
}
}
sum + number
@rustedwolf
rustedwolf / auto-height-folding.css
Created December 12, 2014 16:39
Fluid css fold/unfold animation when having auto height
/*
* Credits goes to +RichBradshaw, from whom I've learned this technique
*/
.container .hidden-container {
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease; /* reverse transition*/
/* remember not to put any borders, paddings here*/
}
.container:hover .hidden-container {
@rustedwolf
rustedwolf / wp_functions.php
Created April 14, 2014 13:06
Usable WP functions
// Timber functions
add_filter('get_twig', 'add_to_twig');
function add_to_twig($twig) {
$twig->addFilter('translate', new Twig_Filter_Function('getTranslation'));
return $twig;
}
function getTranslation($string){
@rustedwolf
rustedwolf / styles.php
Last active August 29, 2015 13:56
Minifies the css files. Refactored code fom stackoverflow.
<?php
if (extension_loaded('zlib')) {
ob_start('ob_gzhandler');
}
header('content-type: text/css; charset: UTF-8');
header('cache-control: must-revalidate');
$offset = 60 * 60;
$expire = 'expires: ' . gmdate('D, d M Y H:i:s', time() + $offset) . ' GMT';
header($expire);
@rustedwolf
rustedwolf / areaToSVGPath.php
Last active June 19, 2017 11:10
Converts HTML map cordinates to SVG path.
<?php
function areaToSVGPath($area) {
$mapPoints = explode(',', $area);
$path = "M" . $mapPoints[0];
$delimiter = " ";
for ($i = 1; $i < count($mapPoints); $i++) {
$path .= $delimiter . $mapPoints[$i];
$delimiter = ($delimiter === " ") ? " L" : " ";
}
@rustedwolf
rustedwolf / raphael.tooltip.js
Last active December 26, 2015 02:29
Raphael: Tooltipdraws a tooltip at certain cordinates.
/**
* Draws a textBox at certain cordinates
*
* @param {object} raphaelPaper
* @param {type} text
* @param {type} cordinates
* @param {type} options that are additional
* @returns {unresolved}
*/
function Tooltip(raphaelPaper, text, cordinates) {