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
class HTTPServerStore
runners: {}
mergeQueries: (queries, data) ->
@merge.apply(
this,
[{}].concat(Object.values(runners).map((runner) ->
runner(data)
))
)
A = function () {};
A.extend = function (Child) {
var proto = Child.prototype;
Child.prototype = new (this);
Child.extend = A.extend.bind(Child);
Object.keys(proto).forEach(function (key) {
Child.prototype[key] = proto[key];
});
Child.prototype.parent = this;
return Child;
@ryasmi
ryasmi / ServerDS.RealTime.coffee
Last active August 29, 2015 14:16
Reactive data store on the server
class RealTimeServerDS extends ServerDS
writeData: (model_coll) ->
@changedData(@runQueries(model_coll))
return this
readData: (model_coll) ->
@changedData(@runQueries(model_coll))
return this
changedData: (id_coll) ->
@ryasmi
ryasmi / DS.coffee
Last active August 29, 2015 14:16
Reactive data store on the client
class DS
data: {}
queries: []
readData: (reader) ->
return reader(@data)
writeData: (model_coll) ->
return @updateData(modelToIdColl(id_coll))
class Server
write: (id_coll) ->
@stores.map((store) ->
store.write(id_coll)
)
return this
read: (store, queries) ->
store.queries = queries
@chunker((model_collection) ->
var collections = {};
collections.users = [{_id: 0, name: 'Anne'}, {_id: 1, name: 'Bob'}, {_id: 2, name: 'Christine'}, {_id: 3, name: 'Daniel'}]
var safeEval = function (code) {
'use strict';
var module, global, GLOBAL;
module = global = GLOBAL = undefined;
return eval('('+code+')');
}.bind(null);
@ryasmi
ryasmi / issue-replies.md
Last active August 29, 2015 14:15
A bunch of replies that I write to issues repeatedly.

Unconfirmed (Follow guidelines)

Hi @CREATOR, thanks for reporting this issue. Please edit your comment to follow our [guidelines](/blob/master/contributing.md). Once you've edited your comment we'll attempt to reproduce your issue.

Learning Locker

Hi @CREATOR, thanks for reporting this issue. Please edit your comment to follow our [bug template](http://docs.learninglocker.net/troubleshooting/). Once you've edited your comment we'll attempt to reproduce your issue.

[Example of the template in use](https://github.com/LearningLocker/learninglocker/issues/533).


Authorities API

Method HTTP request Description
index GET / Gets all of the sub-authorities.
store POST / Creates a new sub-authority.
show GET /id Gets the sub-authority with the given id.
@ryasmi
ryasmi / wrapURLs.js
Last active June 22, 2023 14:47
Wraps all URLs in anchor tags with a `href` and `target` inside some given text.
var wrapURLs = function (text, new_window) {
var url_pattern = /(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}\-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?/ig;
var target = (new_window === true || new_window == null) ? '_blank' : '';
return text.replace(url_pattern, function (url) {
var protocol_pattern = /^(?:(?:https?|ftp):\/\/)/i;
var href = protocol_pattern.test(url) ? url : 'http://' + url;
return '<a href="' + href + '" target="' + target + '">' + url + '</a>';
});
};
@ryasmi
ryasmi / tag.ts
Last active August 29, 2015 14:11
Tag ported to TypeScript
module Tag {
interface AliasOptions {
options: Object,
content: array<Object>,
tagName: string
};
export function tag(name: string) {
tag[name] = (options: Object = {}, arg2: any = []) => {
var content: Array<Object>;