Skip to content

Instantly share code, notes, and snippets.

View gentoid's full-sized avatar
😃

Viktor Lazarev gentoid

😃
View GitHub Profile
@gentoid
gentoid / highlight
Created February 10, 2013 19:41
Highlight text
function highlight(text, words, tag) {
// Default tag if no tag is provided
tag = tag || 'span';
var i, len = words.length, re;
for (i = 0; i < len; i++) {
// Global regex to highlight all matches
re = new RegExp(words[i], 'g');
if (re.test(text)) {
@gentoid
gentoid / breakPoint
Created February 10, 2013 19:38
Breakpoints for adaptive design
function isBreakPoint(bp) {
// The breakpoints that you set in your css
var bps = [320, 480, 768, 1024];
var w = $(window).width();
var min, max;
for (var i = 0, l = bps.length; i < l; i++) {
if (bps[i] === bp) {
min = bps[i-1] || 0;
max = bps[i];
break;
@gentoid
gentoid / callback.php
Created January 22, 2013 11:56
Is it HTTP_X_REQUESTED_WITH?
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') {
return;
}
<?php
$modx = new modX();
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$modx->initialize('mgr');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->exec("UPDATE {$modx->getTableName('modResource')} SET uri = '' WHERE uri_override = 0");
//$modx->call('modResource', 'refreshURIs', array(&$modx));
foreach ($modx->getIterator('modResource', $criteria) as $resource) {
@gentoid
gentoid / style.css
Created January 3, 2013 11:39
CSS3 Circle load rotator
/*** Loader ***/
.loader-ball1 {
background-color: rgba(0,0,0,0);
border:5px solid rgba(0,183,29,.9);
opacity:.5;
border-top:5px solid rgba(0,0,0,0);
border-left:5px solid rgba(0,0,0,0);
border-radius:50px;
box-shadow: 0 0 35px #009720;
width:50px;
<?php die('This file is not really here!');
/**
* ------------- DO NOT UPLOAD THIS FILE TO LIVE SERVER ---------------------
*
* Implements code completion for CodeIgniter in phpStorm
* phpStorm indexes all class constructs, so if this file is in the project it will be loaded.
* -------------------------------------------------------------------
* Drop the following file into a CI project in phpStorm
* You can put it in the project root and phpStorm will load it.
@gentoid
gentoid / what-forces-layout.md
Created October 15, 2015 08:45 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@gentoid
gentoid / sample.coffee
Created June 25, 2015 14:02
CoffeeScript + jQuery event handling
# 1. trigger events
$(document).trigger 'flash:message', { level: 'error', message: 'There was an error' }
# 2. catch events in another place
$(document)
.on 'flash:message', (e, params) =>
if params.level && params.message
@show params.level, params.message # call 'show' method doing something interesting :-)
@gentoid
gentoid / app.po
Created June 1, 2015 12:39
gettext
# English translations for Retina package.
# Copyright (C) 2015 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the Retina package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2015.
#
msgid ""
msgstr ""
"Project-Id-Version: Retina 0.33.2-26-g8a4bb2a\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-06-01 16:37+0400\n"
@gentoid
gentoid / introrx.md
Last active August 29, 2015 14:16 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.