Skip to content

Instantly share code, notes, and snippets.

@BadBastion
BadBastion / 0_reuse_code.js
Last active August 29, 2015 14:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@BadBastion
BadBastion / javascript_resources.md
Last active August 29, 2015 14:17 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@BadBastion
BadBastion / css_resources.md
Last active August 29, 2015 14:17 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.

Libraries

  • 960 Grid System - An effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.
  • Compass - Open source CSS Authoring Framework.
  • Bootstrap - Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
  • Font Awesome - The iconic font designed for Bootstrap.
  • Zurb Foundation - Framework for writing responsive web sites.
  • SASS - CSS extension language which allows variables, mixins and rules nesting.
  • Skeleton - Boilerplate for responsive, mobile-friendly development.

Guides

@BadBastion
BadBastion / indexof-min.js
Created September 29, 2015 20:11 — forked from revolunet/indexof-min.js
IE<9 indexOf polyfill
if(!Array.prototype.indexOf){Array.prototype.indexOf=function(b){var a=this.length>>>0;var c=Number(arguments[1])||0;c=(c<0)?Math.ceil(c):Math.floor(c);if(c<0){c+=a}for(;c<a;c++){if(c in this&&this[c]===b){return c}}return -1}};
@BadBastion
BadBastion / new_gist_file_0
Created October 10, 2015 18:37
Javascript getters and setters
var person = {sutff:"stuff"};
Object.defineProperty(person, 'fullName', {
get: function() {
return firstName + ' ' + lastName;
},
set: function(name) {
var words = name.split(' ');
this.firstName = words[0] || '';
this.lastName = words[1] || '';
}
defmodule Test do
defp add(product, {i, list_i}, {j, list_j}, max) do
p = [{elem(list_i, i), elem(list_j, j)} | product]
reverse(p, {j, list_i}, {i+1, list_j}, max)
end
defp reverse(product, {i, list_i}, {j, list_j}, max) do
p = [{elem(list_i, i), elem(list_j, j)} | product]
defmodule T do
defp init_cursor(dimension) do (for _ <- 1..dimension, do: 0) end
defp increment_cursor(cursor, depth) do
max = depth-1
cursor
|>List.foldr(
{1, false, []},
@BadBastion
BadBastion / BreadthFirst.ex
Last active May 11, 2017 01:10
Improved breadth first product
defmodule BreadthFirst do
defp init_cursor(dimension) do (for _ <- 1..dimension, do: 0) end
defp increment_cursor(cursor, depth, max, carry) do
cursor
|>List.foldr(
{carry, false, []},
fn elem, {carry, unique, acc} ->
case elem + carry do
@BadBastion
BadBastion / increment.ex
Last active July 19, 2017 18:34
Increment LL cursor
def increment(enums, head) do
# enums, and all of their heads (start of list)
# accumulator = {carry, enums}
zip(enums, head)
|> foldr({true, []}, fn
{[_ | []], head}, {true, acc} -> {true, [head | acc]}
# {if the list has no more elements} and {carry in} -> {carry out and set back to begining on list (head)}
{[_ | tail], _head}, {true, acc} -> {false, [tail | acc]}
# {if the list does have more elements} and {carry in} -> {do NOT carry out and move to next element in list (tail)}
{enum, _head}, {false, acc} -> {false, [enum | acc]}
@BadBastion
BadBastion / same.ex
Last active July 19, 2017 21:10
Both are basically the same
[1,2,3] |> map(fn number -> my_function(number) end)
[1,2,3] |> reduce([], fn number, acc -> acc ++ [ my_function(number) ] end)