Skip to content

Instantly share code, notes, and snippets.

View arnemart's full-sized avatar

Arne Martin Aurlien arnemart

View GitHub Profile
@arnemart
arnemart / important.js
Created February 21, 2017 10:07
PostCSS plugin to make every declaration !important
var postcss = require('postcss');
module.exports = postcss.plugin('postcss-everything-is-important', function () {
return function (css) {
css.walkDecls(function (decl) {
decl.important = true;
});
};
});
@arnemart
arnemart / lastNDigitsOfPi.js
Created November 11, 2015 08:51
lastNDigitsOfPi.js
function lastNDigitsOfPi(n) {
return Math.PI.toFixed(Infinity).slice(-n);
}
@arnemart
arnemart / goooal.js
Last active November 10, 2015 13:41
GOOOOOOOOAL
function oo(n) {
return Object.defineProperties({}, {
al: { get: () => 'go' + [...Array(n + 1)].join('o') + 'al' },
o: { get: () => oo(n + 1) }
});
}
var go = oo(0);
console.log(go.al); //=> goal
@arnemart
arnemart / .irbrc
Last active March 22, 2023 12:08
Pretty print json from irb
def ppjson(json)
puts _ppjson(json)
end
def _ppjson(json)
json = JSON.parse(json) if json.class == "String"
JSON.pretty_generate(json)
end
class String
@arnemart
arnemart / gist:1e27a8e1963cc9eeaf2d
Last active August 29, 2015 14:13
It's totally thread safe, don't worry about it
class TrueClass
def self.setVal(val)
$val = val
end
def <(n)
$val < n
end
end
@arnemart
arnemart / gist:511aa4a098d3a6b67539
Last active August 29, 2015 14:11
The ultimate flexible database schema
CREATE TABLE "database"
(
id serial NOT NULL,
name text,
CONSTRAINT database_pkey PRIMARY KEY (id)
)
CREATE TABLE "table"
(
id serial NOT NULL,
@arnemart
arnemart / gist:c26aeddcb7d719b45529
Last active August 29, 2015 14:05
Cursors example
var React = require('react');
var Immutable = require('immutable-with-cursors');
var mainComponent = React.createClass({
getInitialState: function() {
return this.props;
},
render: function() {
return React.DOM.ul(
null,
quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort (pivot:rest) = (quicksort smaller) ++ [pivot] ++ (quicksort greater)
where
smaller = filter (<= pivot) rest
greater = filter (> pivot) rest
merge :: Ord a => [a] -> [a] -> [a]
merge [] [] = []
@arnemart
arnemart / gist:8684859
Created January 29, 2014 09:56
$.delayLink
(function($) {
$.fn.delayLink = function(fn, options) {
var settings = $.extend(options, {
timeout: 100
});
$(this).on('click', function(e) {
e.preventDefault();
var went = false;
var link = this;
var go = function() {
@arnemart
arnemart / LICENSE.txt
Last active March 8, 2018 11:37 — forked from 140bytes/LICENSE.txt
Safely access nested object or array properties in 127 bytes
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE