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
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,
@MagnusThor
MagnusThor / Array.find.js
Created January 25, 2016 08:33
Array.find....
if (!Array.prototype.find) {
Array.prototype.find = function (predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
@MagnusThor
MagnusThor / OnOpen_Arin.cs
Created January 21, 2016 08:06
Keep alive using System.Timers.Timer();
public override async Task OnOpened() {
var t = new System.Timers.Timer();
// do your onOpen Stuff...
t.Interval = 1000 * 15;
t.Elapsed += (sender, args) => {
this.Invoke(new {
ts = DateTime.Now.Second
}, "ping");
};
t.Start();
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<script src="js/XSockets.latest.js"></script>
<script src="js/XSockets.WebRTC.latest.js"></script>
@MagnusThor
MagnusThor / gist:00f98d53843aeb635672
Created January 7, 2016 17:33
Create transcripts using webkitSpeechRecognition by attaching a mediaStream audioTrack
var AudioTrackSpeechLog = (function () {
"use strict";
var ctor = function (track, completed, interim, lang) {
var self = this;
this.recognizing = false;
this.finalTranscript = "";
if (('webkitSpeechRecognition' in window)) {
this.recognition = new webkitSpeechRecognition();
this.recognition.continuous = true;
this.recognition.interimResults = true;