Skip to content

Instantly share code, notes, and snippets.

@chriszf
chriszf / gist:2342247
Created April 9, 2012 08:07
FizzBuzz without conditionals
# SCREW YOU CONDITIONALS
def fizzbuzz(n):
fizzes = [1, 0, 0]
buzzes = [2, 0, 0, 0, 0]
words = [None, "Fizz", "Buzz", "FizzBuzz"]
for i in range(1, n):
words[0] = i
print(words[fizzes[i%3] + buzzes[i%5]])
@manpages
manpages / the-case-for-gist-blogging.org
Created April 28, 2012 06:16
Why do I love to use gist as a blog engine?

The case for Gist blogging

Why to bother?

The posts people write in blogs can be classified in two groups:

  • those that are going to be (or should be) maintained, expressing the real time information (like books one reads or read, todo lists, lecture notes, etc),
  • those that express the momentary thoughts of a writer on an event or activity.

Maintaining the post

While first ones can be managed using standart blog engines (livejournal, blogger, etc) via «Edit post» option, that’s hardly

@ggilder
ggilder / fizz.rb
Created June 8, 2012 05:14
Fizzbuzz bitwise math
messages = [nil, "Fizz", "Buzz", "FizzBuzz"]
acc = 810092048
(1..100).each do |i|
c = acc & 3
puts messages[c] || i
acc = acc >> 2 | c << 28
end
# Explanation
#
@buzzdecafe
buzzdecafe / compose.js
Last active March 27, 2017 16:22
curried binary compose
// first try:
R.cc = R.curry(function cc(f, g) {
return R.curryN(g.length, function() {
var gargs = Array.prototype.slice.call(arguments, 0, g.length);
var fargs = Array.prototype.slice.call(arguments, g.length);
return f.apply(this, [g.apply(this, gargs)].concat(fargs));
});
});
// so this works:
@CMCDragonkai
CMCDragonkai / higher_kinded_types_in_rust_and_haskell.md
Last active July 10, 2024 12:38
Rust/Haskell: Higher-Kinded Types (HKT)

Rust/Haskell: Higher-Kinded Types (HKT)

A higher kinded type is a concept that reifies a type constructor as an actual type.

A type constructor can be thought of in these analogies:

  • like a function in the type universe
  • as a type with a "hole" in it
@vvgomes
vvgomes / foo.js
Last active August 10, 2021 18:10
Ramda vs Lodash
var _ = require("lodash");
var R = require("ramda");
var companies = [
{ name: "tw", since: 1993 },
{ name: "pucrs", since: 1930 },
{ name: "tw br", since: 2009 }
];
var r1 = _(companies).chain()
@paulirish
paulirish / what-forces-layout.md
Last active July 22, 2024 06:32
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@Avaq
Avaq / combinators.js
Last active July 15, 2024 14:46
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@Avaq
Avaq / fold.js
Last active March 5, 2018 12:28
Functional JavaScript cookbook
//Combinators
const I = x => x;
//List manipulation
const head = xs => xs[0];
const tail = xs => xs.slice(1);
const append = x => xs => [...xs, x];
//Iteration
const foldl = f => y => xs => xs.length > 0 ? foldl(f)(f(y)(head(xs)))(tail(xs)) : y;
@Avaq
Avaq / SKI.js
Last active April 23, 2020 18:36
Combinatory Fun
const S = f => g => x => f(x)(g(x))
const K = x => y => x
const I = S(K)(K)
const B = S(K(S))(K)
const C = S(S(K(B))(S))(K(K))
const A = S(K(I))
const T = C(A)
const W = S(S)(K(I))