Skip to content

Instantly share code, notes, and snippets.

View kangax's full-sized avatar

Juriy Zaytsev kangax

View GitHub Profile
@kangax
kangax / BEM.html
Last active August 29, 2015 14:06
<!--
<component-name>[--modifier-name|__descendent-name]
.component {}
.component__descendant {}
.component--modifier {}
-->
<article class="tweet tweet--is-expanded">
<header class="tweet__header">
function formatSchedule(schedules) {
var dayAbbr = [ 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс' ];
function dayIndicesToWord(indices) {
if (areDayIndicesSequential(indices)) {
return dayAbbr[indices[0]] + '-' + dayAbbr[_.last(indices)];
}
else {
var daysAsWords = _.map(indices, function(index) {
return dayAbbr[index];
function formatSchedule(schedules) {
var dayAbbr = [ 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс' ];
function dayIndicesToWord(indices) {
if (areDayIndicesSequential(indices)) {
return dayAbbr[indices[0]] + '-' + dayAbbr[_.last(indices)];
}
else {
var daysAsWords = _.map(indices, function(index) {
return dayAbbr[index];
@kangax
kangax / gist:a02bcb082cd8a7d36d0a
Last active August 29, 2015 14:02
Chrome DevTools suggestions
  • Being able to edit JS source after prettifying #103143

  • Jump to function definition (or see prettifyed function definition) #248647

  • Better JS prettifying (e.g. newlines after ",") #383933

  • Cmd/Ctrl + P in sources to do fuzzy matching (e.g. "all js" doesn't find "all.js", like Sublime does) #383945

  • Smarter console auto-suggest

    • alert(console.) doesn't show suggestions
console.highlight = function(text, sample) {
var escapedSample = sample.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
var reSample = new RegExp(escapedSample, 'g');
var args = [''];
var highlightedText = text.replace(reSample, function(match) {
args.push('background-color: #ffc', 'background-color: none');
return '%c' + match + '%c';
});
args[0] = highlightedText;
console.log.apply(console, args);

RegExp.escape(string)

Computes a new version of a String value in which certain characters have been escaped, so that the regular expression engine will interpret any metacharacters that it may contain as character literals.

When the escape function is called with one argument string, the following steps are taken:

  1. Let string be ToString(string).
  2. ReturnIfAbrupt(string).
  3. Let length be the number of characters in string.
  4. Let R be the empty string.
// create new card
$('.js-add-list-popover').click();
var d = new Date();
var year = (d.getFullYear()+'').substring(2);
var month = d.getMonth() + 1;
var day = d.getDate();
var cardName = 'Published (' + month + '-' + day + '-' + year + ')';
$('.js-list-name').val(cardName);
(function(d, s) {
var deps = {
twitter: [
"//platform.twitter.com/widgets.js",
"twitter-wjs"
],
facebook: [
"//connect.facebook.net/en_US/all.js#xfbml=1",
"facebook-jssdk"
// run on http://browser.primatelabs.com/mac-benchmarks
function findFirst(text) {
return $('td a').filter(function(i, el){ return $(el).text().indexOf(text) > -1 }).eq(0).closest('tr');
}
var mine = findFirst('MacBook Pro (17-inch Early 2011)');
var topMbp = findFirst('MacBook Pro');
$('tbody tr').hide().eq(0).show();
var URL = require('url'),
HTTP = require('http'),
Canvas = require('canvas'),
Image = Canvas.Image,
img = new Image(),
canvas = new Canvas(200,200),
ctx = canvas.getContext('2d'),
// throws "Error: Image given has not completed loading"