Skip to content

Instantly share code, notes, and snippets.

View VadimBrodsky's full-sized avatar

Vadim Brodsky VadimBrodsky

View GitHub Profile

Tracking Event on File Download in Google Analytics

function trackDownload(link) {
  var fileName = link.getAttribute('href');
  fileName  = fileName.split('/').pop();
  
  // Track event in GA
  _gaq.push(['_trackEvent', 'Download', 'Resources Download', fileName]);
}
@VadimBrodsky
VadimBrodsky / jsbooks.md
Last active December 8, 2015 04:11
JavaScript Books
@VadimBrodsky
VadimBrodsky / sudoku.rb
Last active October 15, 2015 00:48
Sudoku solver
require 'pry'
#
# +---+---+---+
# | | | |
# | 3 | 5 | 4 |
# | | | |
# +---+---+---+
#
@VadimBrodsky
VadimBrodsky / git-tricks.md
Created October 20, 2015 23:33
git tricks

Ignoring files from local work folder, without altering the .gitignore.

git update-index --assume-unchanged <file1> <file2> <file3>
// Bonfire: Find the Longest Word in a String
// Author: @vadimbrodsky
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function findLongestWord(str) {
return str.toLowerCase().split(' ').sort(function(a, b) {
if (a.length < b.length) {
return 1;
} else if (a.length > b.length) {
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@VadimBrodsky
VadimBrodsky / friendly_urls.markdown
Created December 16, 2015 03:20 — forked from cdmwebs/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@VadimBrodsky
VadimBrodsky / Structure Top Level.md
Last active December 22, 2015 21:07
Craft Snippets

Source -- http://craftcms.stackexchange.com/a/6996

Untested, but you should be able to do this by using the [merge filter in Twig][1] to join the two results together.

Get the top level 'landing page' for this section:

{% set landingPage = entry.getAncestors().level(1) %}