Skip to content

Instantly share code, notes, and snippets.

View kangax's full-sized avatar

Juriy Zaytsev kangax

View GitHub Profile
@kangax
kangax / backbone.js
Last active October 17, 2015 05:07
bacon vs. backbone vs. react (just seeing how bacon's paradigm compares with other approaches)
var RegisterForm = Backbone.View.extend({
ui: {
username: '.username',
fullname: '.fullname',
register: '.register-btn',
loader: '.loader',
feedback: '.feedback'
}
events: {
'input username, fullname': 'onInput',

Sept 22 2015 Meeting Notes

Allen Wirfs-Brock (AWB), Sebastian Markbage (SM), Jafar Husain (JH), Eric Farriauolo (EF), Caridy Patino (CP), Mark Miller (MM), Adam Klein (AK), Michael Ficarra (MF), Peter Jensen (PJ), Domenic Denicola (DD), Jordan Harband (JHD), Chip Morningstar (CM), Brian Terlson (BT), John Neumann (JN), Dave Herman (DH), Brendan Eich (BE), Rick Waldron (RW), Yehuda Katz (YK), Jeff Morrison (JM), Lee Byron (LB), Daniel Ehrenberg (DE), Ben Smith (BS), Lars Hansen (LH), Nagy Hostafa (NH), Michael Saboff (MS), John Buchanan (JB), Gorkem Yakin (GY), Stefan Penner (SP)

On the phone: Mark Miller (MM), Dan Gohmann (DG), John McCutchan (JMC)

(Need attendance list)

@kangax
kangax / quicksort.hs
Last active September 5, 2021 19:44
Haskell-inspired quick sort in ES6
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort (filter (<=x) xs)
biggerSorted = quicksort (filter (>x) xs)
in smallerSorted ++ [x] ++ biggerSorted
var TodoApp = Backbone.View.extend({
template: Handlebars.compile(
'<div>\
<h3>TODO</h3>\
{{#each items}}\
{{ this }}\
{{/each}}\
<form>\
<input value="{{ text }}">\
<button>Add #{{ items.length }}</button>\
@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.