Skip to content

Instantly share code, notes, and snippets.

View MagnusThor's full-sized avatar
🏠
Working from home

Magnus 'Bagzy' Thor MagnusThor

🏠
Working from home
  • Freelancer & member of coloquium
  • Sweden
View GitHub Profile
@MagnusThor
MagnusThor / es6Proxies_TypeScript_labs.ts
Created March 21, 2017 14:43
ES6 Proxies , Observable , change tracking , deep / plain
export class ProxyWrapperBase {
constructor() {
}
onChange(target: Object, key: PropertyKey, newValue: any, oldValue: any){
}
}
export class BinaryMessage {
Buffer: ArrayBuffer;
private header: Uint8Array
GetMessage(buffer: ArrayBuffer): any {
let headerLen = 8;
let header = new Uint8Array(buffer, 0, headerLen);
let payloadLength = ThorIO.Client.Utils.arrayToLong(header);
@MagnusThor
MagnusThor / ChatController.ts
Last active August 10, 2016 12:24
An example of how to build a "chat" using on a state-full thor-io controller (typescript,nodejs,express)
import {
ThorIO,CanInvoke,ControllerProperties,CanSet
} from "thor-io.vnext"
// simple model
class ChatMessage
{
text:string;
}
// location controllers/controller.js
// this will store the messages and act as a fake db .-)
var fakeDb = {
messages : []
};
var ChatController = (function (db) {
// find out who this message targets?
MyControllers.PeerController =(function () {
var randomString = function () {
return Math.random().toString(36).substring(7);
};
var chatMessage = function (text,nickname) {
this.text = text;
this.created = new Date();
};
@MagnusThor
MagnusThor / app.js
Created February 16, 2016 16:03
a goatish favour for JJ
// Skapa vår app
angular.module("jonas.app", []);
// the controller
(function (angular) {
var myController = function($scope,myService) {
@MagnusThor
MagnusThor / zippyTheZebra.cs
Created February 4, 2016 17:04
Task Async Helper Stub
private IEnumerable<FakeOrder> CallServiceToFind(string query)
{
System.Threading.Thread.Sleep(1000);
return orders.Where(p => p.ProjectName.ToLower().Contains(query.ToLower())).Take(400);
}
private Task<IEnumerable<FakeOrder>> _task { get; set; }
public async Task FindOrder(string query,int chunks = 10,int wait = 1000)
{
try
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using XSockets.Core.Common.Socket;
using XSockets.Core.Common.Utility.Logging;
using XSockets.Core.XSocket.Helpers;
using XSockets.Plugin.Framework;
@MagnusThor
MagnusThor / Watchers.js
Created February 3, 2016 08:45
Count scope.$watch using data-wcount="true" attributes
var Watchers = {
getWatchers : function(root) {
root = angular.element(root || document.documentElement);
function getElemWatchers(element) {
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
var scopeWatchers = getWatchersFromScope(element.data().$scope);
var watchers = scopeWatchers.concat(isolateWatchers);
angular.forEach(element.children(), function (childElement) {
watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
});
@MagnusThor
MagnusThor / seed
Created January 29, 2016 13:31
seed.js
$scope.myArray = [];
for (var i = 1; i < 200;i++) {
$scope.myArray.push({
id: i,
firstName: (Math.random() * 9e6).toString(36),
lastName: (Math.random() * 9e6).toString(36),
city: (Math.random() * 9e6).toString(36),
zipcode: i * 100,