Skip to content

Instantly share code, notes, and snippets.

View ryasmi's full-sized avatar
🐿️
Checks emails once per day Mon-Fri

Ryan Smith ryasmi

🐿️
Checks emails once per day Mon-Fri
View GitHub Profile
@ryasmi
ryasmi / resembles.js
Last active December 17, 2015 06:19
Determines if an object resembles another object (obj). If x resembles y, then x contains some of y's attributes. xRy => x.keys (subset of) y.keys
// Using func. https://gist.github.com/ryansmith94/5564105
func("resembles", function (obj) {
var self = this;
var keys = Object.keys(self);
var len = keys.length;
var key = 0;
return (function check() {
if (self[keys[key]] === obj[keys[key]]) {
key += 1;
var x = (function () {
var a = function () {
return s;
};
var b = function () {
return s.a();
};
var s = {a: a, b: b, name: "x"};
return s;
}());
@ryasmi
ryasmi / crazyNewFunction.js
Last active December 22, 2015 08:19
Some crazy `new Function` use.
var crazy = function () {
var val = 10;
return {
val: function () { return val; },
changeVal: function () { val = 11; },
changeGlobal: new Function ('val = 12;')
};
};
@ryasmi
ryasmi / languageX.md
Last active December 22, 2015 09:28
If you could write your own programming language what would it be like?

What and Why

I'd like a language that...

  1. has a small amount of syntax
  2. has a small set of functions
  3. is extended using the syntax provided not by adding more syntax
  4. can be extended by implementors by providing extra native functions without adding syntax
  5. does not concern itself with hardware
@ryasmi
ryasmi / interfaceX.md
Last active December 22, 2015 09:29
A proposed specification for creating/rendering interfaces.

Interface X

A proposed specification for creating/rendering interfaces.

This is simply a proposed specification and is by no means complete.

1 Goal

It's possible that in the future we may have displays that do not use pixels. In addition interfaces are becoming more complex and therefore need to be more modular so that they remain easy to create whilst still allowing customisation. This specification aims to provide the minimal requirements to represent a 3D interface.

2 Proposal

A interface element represented using JSON.

@ryasmi
ryasmi / numberActor.js
Last active December 22, 2015 11:49
"Loose example" of an number as an actor in JavaScript (I think - where a function is an actor).
function number(value) {
value = Number(value);
return function (fn) {
if (fn === 'add') {
if (typeof arguments[1] === 'function') {
return arguments[1]('add', value);
}
return number(value + (Number(arguments[1]) || 0));
} else if (fn === 'equals') {
if (typeof arguments[1] === 'function') {
@ryasmi
ryasmi / actor.js
Last active December 22, 2015 15:59
var actor = function (actor, state) {
return function callee() {
return actor.apply(this, Array.prototype.slice.call(arguments).concat([state, callee.caller]));
};
};
@ryasmi
ryasmi / ensureArray.js
Created September 22, 2013 13:38
Ensures that an object is an Array.
// Ensures that an object (obj) is an Array.
var ensureArray = function (obj) {
return Array.isArray(obj) ? [obj] : obj;
};
@ryasmi
ryasmi / Future Code Completion.md
Last active December 23, 2015 17:59
This an example of what I hope future code completion is like. Could use "unification" to decide if a function is the same as another.

UserX/OneOps.code

# {x} + 1
addOne (x) => add x 1

UserY/TenAddOne.code (before completion)

log = import log from 'console'
@ryasmi
ryasmi / myUnit.js
Last active December 23, 2015 18:19
Treating classes and modules as functions (units) with dependencies. Shows that classes and modules can be defined in the same way, but used differently (like classes and modules).
(this.myUnit = function myUnit() {
var self = {};
self.myMethod = function () {
return 'hello world';
};
return self;
}).needs = {
// Has no dependencies.