Skip to content

Instantly share code, notes, and snippets.

View gskema's full-sized avatar

Gytis Šk. gskema

  • Kaunas, Lithuania
View GitHub Profile
@gskema
gskema / color-gradient.js
Last active March 2, 2024 22:14
Generate gradient color from 2 or 3 colors using JavaScript. Example: https://jsfiddle.net/e18g5f3L/
/**
* You may use this function with both 2 or 3 interval colors for your gradient.
* For example, you want to have a gradient between Bootstrap's danger-warning-success colors.
*/
function colorGradient(fadeFraction, rgbColor1, rgbColor2, rgbColor3) {
var color1 = rgbColor1;
var color2 = rgbColor2;
var fade = fadeFraction;
// Do we have 3 colors for the gradient? Need to adjust the params.
@gskema
gskema / script.js
Created May 19, 2016 18:14
Bootstrap screen width change event JS
var resizeBuffer = null;
var prevWidthName = getWindowWidthName();
$(window).on('resize', function () {
clearTimeout(resizeBuffer);
resizeBuffer = setTimeout(function() {
var newWidthName = getWindowWidthName();
if (newWidthName != prevWidthName) {
prevWidthName = newWidthName;
$(document).trigger(newWidthName);
}
@gskema
gskema / paginator.php
Created February 4, 2016 12:54
Binary pagination generator
<?php
/**
* Generates a pagination array
*
* @param int $total_items
* @param int $page_size
* @param int $current_page
* @return array $pagination
*/
@gskema
gskema / convert.php
Created February 4, 2016 12:53
Integer number in Lithuanian words
<?php
/**
* Converts an integer number to a word in Lithuanian language.
*
* @param int $number Integer number to be converted into words
* @param array|bool $units Units array like array(0 => šimtas, 1 => šimtai, 2 => šimtų);
* @param bool $one If false, word "vienas" is omitted
* @return string
*/
@gskema
gskema / list-grid.html
Last active December 27, 2017 20:40
Bootstrap 3 varied height columns
<style type="text/css">
/*
* Allows to usage of <ul> as .row and <li> as .col-**-*
* Benefit of using <li> is that the column can be of varied height,
* unlike when using div.row - columns collapse when heights are different.
* The tricky part is to eliminate whitespaces between <li></li> tags.
*
* Usage: <ul class="list-grid row">
* <li class="col-md-3">...</li>
*
@gskema
gskema / index.html
Last active December 5, 2015 18:32
Bootstrap 3 Numeric Up and Down control (spinbox, spinner)
<div class="spinbox" data-min="1" data-max="10" data-step="2">
<input class="form-control spinbox-input" type="text" value="1">
<div class="spinbox-buttons">
<button class="spinbox-up btn btn-default btn-xs" type="button">+</button>
<button class="spinbox-down btn btn-default btn-xs" type="button">-</button>
</div>
</div>
<script type="text/javascript">
// jQuery must be available before binding events
@gskema
gskema / db.php
Created September 1, 2015 11:15
PHP PDO bulk INSERT
<?php
class Db
{
public function batchInsert($table, array $rows, array $columns = array())
{
// Is array empty? Nothing to insert!
if (empty($rows)) {
return true;
}
@gskema
gskema / blockuserinfo.php
Created May 10, 2015 08:28
Clean method override
<?php
if (!defined('_PS_VERSION_'))
exit;
class BlockUserInfoOverride extends BlockUserInfo
{
public function hookDisplayTop($params)
{
$this->smarty->assign(array(
@gskema
gskema / blockuserinfo.php
Created May 10, 2015 08:21
Minor method modification: 'company_name'
<?php
if (!defined('_PS_VERSION_'))
exit;
class BlockUserInfoOverride extends BlockUserInfo
{
public function hookDisplayTop($params)
{
if (!$this->active)
@gskema
gskema / blocktopmenu.php
Created May 10, 2015 07:56
Unextendable class methods
class BlockTopMenu extends Module
{
private $_menu = '';
private $_html = '';
private $user_groups;
...
private function getMenuItems(){ ... }