This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // javascript | |
| var app = angular.module("someApp", []); | |
| app.controller("someController", function($scope) { | |
| $scope.name = "Liam Neeson"; | |
| }); | |
| // html: two-way data binding ("name") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Credits: https://www.clayallsopp.com/posts/from-backbone-to-react/ | |
| */ | |
| ProfileView = Backbone.View.extend({ | |
| render: function() { | |
| var template = _.template($("#profile-view-template").html()); | |
| $(this.el).html(template); | |
| // Add a subview |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Credits: https://gabrieleromanato.name/spaghetti-code-in-jquery/ | |
| */ | |
| $('#foo').addClass('bar').parent().find('li').addClass('item').click(function() { | |
| //... some click handler. good luck maintaining this piece of code! | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Credits: https://www.codementor.io/brainyfarm/jquery-vs-vanilla-javascript-deciding-on-what-to-use-6b79xdmrv | |
| */ | |
| // jquery! | |
| $(el).fadeIn(); | |
| // javascript! | |
| function fadeIn(el) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn transform [xs] | |
| (if (empty? xs) | |
| nil | |
| (concat (map #'+ xs (rest xs)) | |
| (list 1)))) | |
| (defn pascal [n] | |
| (if (zero? n) | |
| nil | |
| (cons 1 (transform (pascal (- n 1)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| const word_bank = ['alex', 'ammar', 'matt', 'jimmy', 'foo', 'bar', 'dab']; | |
| // Calculate the min number of edits to transform string i into string j. | |
| // Based on the Levenshtein Distance: https://en.wikipedia.org/wiki/Levenshtein_distance | |
| const fuzzy = (i, j) => { | |
| // if i or j has no length, return length of the other | |
| if (!i.length) return j.length; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| /** | |
| * Fake Protocol Parser | |
| * V8 Optimization: http://mrale.ph/s3/nodecamp.eu/#15 | |
| * | |
| * PROTOCOL: | |
| * _ _ _ _ _ _ \u0000 _ _ _ _ _ _ _ .... | |
| * DATA LENGTH PAYLOAD | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Inspiration: http://homepages.inf.ed.ac.uk/wadler/papers/frege/frege.pdf | |
| // MATH | |
| g(x, y) = x * x + y * y // generic sum-of-squares function | |
| g(x, y) = (lambda(x), lambda(y): x * x + y * y (u))(v) for all values of x and y // lambda calculus representation | |
| // Reduction sequence, given x = 3, and y = 4: | |
| (lambda(x), lambda(y): x * x + y * y (3))(4) // apply 3 to x, then y to 4 | |
| (lambda(y): 3 * 3 + y * y)(4) // this function can be repeatedly used to compute 3 * 3 + y * y for any y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict' | |
| /* | |
| Quick and dirty Set access vs. Array access time benchmarking | |
| */ | |
| // Create arrays of arbitrary length betwen 1 and n | |
| const arbitrary_data = (n) => Array(Math.ceil(Math.random() * n)).fill().map(x => Math.random()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| grep -o . input.txt | sort | uniq -c | sort -r | sed 's/[0-9]*//g' | tr -d '\n ' | cut -d _ -f 1 | |
| # 1) separate each char by newline (ex. a \n c \n f ...) | |
| # 2) sort by char (ex. a \n a \n a \n c \n f \n f) | |
| # 3) count frequency of each char (ex. 3 a \n 1 c \n 2 f) | |
| # 4) sort by counts, descending (ex. 3 a \n 2 f \n 1 c) | |
| # 5) remove all digits (ex. a \n f \n c) | |
| # 6) remove all newline chars and white spaces (ex. afc) | |
| # 7) keep all chars until the underscore |
NewerOlder