Skip to content

Instantly share code, notes, and snippets.

@kalinchernev
kalinchernev / char-reverse.py
Created November 25, 2014 21:16
Reverse chars of a string
def reverse(string):
buffer = []
for char in string:
buffer.insert(0, char)
reversed = ''.join(buffer)
return reversed
@kalinchernev
kalinchernev / center-method.js
Created December 11, 2014 12:47
jQuery method to center an element on the window
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
$(window).scrollLeft()) + "px");
return this;
}
@kalinchernev
kalinchernev / install.php
Created May 29, 2015 10:37
Small helper feature revert all components
/**
* Helper to revert all components within a feature.
* @param $feature_machine_name
*/
function _feature_revert_all($feature_machine_name) {
$feature = features_get_features($feature_machine_name);
$components = array_keys($feature->info['features']);
features_revert(array($feature_machine_name => $components));
}
@kalinchernev
kalinchernev / SassMeister-input.scss
Created October 12, 2015 10:29
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
$internal_links_patterns: 'beta.ec.europa.eu' 'devcloud.acquia-sites.com' 'webgate.ec.europa.eu';
@mixin internal-icon($patterns) {
@each $url in $patterns {
&:not([href*="#{$url}"]) {
@content
@kalinchernev
kalinchernev / README.md
Last active December 13, 2015 22:31 — forked from benjie/README.md
Long Live CoffeeScript and Long Live ES6

Long Live CoffeeScript and Long Live ES6

Clearly ES6 is a huge improvement over ES5, and tools like [6to5][] allow us to use these cool features now. I was reading [Replace CoffeeScript with ES6][replace coffeescript] by [Blake Williams][] and thought it was a great summary of how ES6 solves many of the same problems that CoffeeScript solves; however I'd like to comment on a few of Blake's points and talk about why I'll be sticking with CoffeeScript.

Classes

Classes in ES6 (like many of the syntax changes in ES6) are very similar to the CoffeeScript equivalent. To support browsers that are not fully ES5 compliant (e.g. IE8-), however, we still can't really use getters/setters, so ignoring these the comparison is:

@kalinchernev
kalinchernev / gist:6867262
Last active December 24, 2015 21:39
JavaScript function to return an extension for a filename input as a string
// @params string - a string containing a file name
// @return string - the file extension (with no period) if it has one, otherwise false
function getFileExtension(string) {
if (typeof(string) === 'string' && (string.indexOf(".") !== -1)){
var dot=string.indexOf(".");
return string.substring(dot+1, i.length)
} else {
return false;
@kalinchernev
kalinchernev / positioning.css
Created October 23, 2013 08:05
Positioning demonstration page
/*
* static - default
* fixed - scrolls with the page
* absolute - top left is starting point
* relative - same as absolute, but starting from static position; Parent elements remain as they are.
* inherit - not well for older IE
*/
body {
background: #f6f6f6;
@kalinchernev
kalinchernev / fluid_box_inner_bottom_center.html
Created December 13, 2013 12:37
Fluid box with inner box on the bottom in the middle
<!DOCTYPE html>
<html>
<head>
<title>Fluid box with inner box on the bottom in the middle</title>
<style type="text/css">
.outer {
background: #ccc;
border: 1px solid red;
position: relative;
height: 250px;
@kalinchernev
kalinchernev / WebDevSetup.sh
Last active January 4, 2016 00:28
Init for bash to setup LAMP environment on Ubuntu 12.04 64 bit
#!/bin/bash
# Start this script at newly installed Ubuntu 12.04 LTS
# The script will install all necessary software for setting up a web development environment
#
# Ubuntu fixes
# - Install the package to fix missing skype icon on toolbar
#
# LAMP environment
# - apache2
# - php5
@kalinchernev
kalinchernev / special.php
Created January 21, 2016 14:58
One of my favorite Drupal-specific interceptions: if you are a president ...
/**
* Implements hook_field_group_pre_render().
*/
function cwt_biography_field_group_pre_render(&$element, $group, &$form) {
if ($node = menu_get_object('node')) {
if ($node->type == 'biography' && $role = field_get_items('node', $node, 'field_biography_role')) {
$role_term = taxonomy_term_load($role[0]['tid']);
$is_president = !$role_term ? FALSE : _commissioner_uuid_is('president', $role_term->uuid);
if ($is_president && $group->label == 'Responsibilities') {
$group->label = t('Role');