Skip to content

Instantly share code, notes, and snippets.

Einar Otto Stangvik einaros

Block or report user

Report or block einaros

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:2956187

Text payload

Roundtrips of 64 B text payloads: node-0.7.12 6% faster
Roundtrips of 16 kB text payloads: node-0.7.12 26% faster
Roundtrips of 128 kB text payloads: node-0.7.12 34% faster
Roundtrips of 1 MB text payloads: node-0.7.12 35% faster

Binary payload

Roundtrips of 64 B binary payloads: node-0.7.12 4% faster
@einaros
einaros / gist:1452218
Created Dec 9, 2011
ws server example
View gist:1452218
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 8080});
wss.on('connection', function(ws) {
ws.on('message', function(message) {
console.log('received: %s', message);
});
ws.send('something');
});
View gist:1452010
$ npm install -g ws
$ wscat -c ws://echo.websocket.org -p 8
connected (press CTRL+C to quit)
> hi there
< hi there
> are you a happy parrot?
< are you a happy parrot?
View gist:1431539
var WebSocket = require('ws')
, ws = new WebSocket('ws://www.host.com/path');
ws.on('open', function() {
ws.send('something');
});
ws.on('message', function(message) {
console.log('received: %s', message);
});
View gist:1269763
var circleCenterPt = new paper.Point(150, 300);
var circleRadius = 75;
var sineWaveLength = 300;
var cosineWaveLength = 300;
paper.setup($('canvas')[0]);
var sineWaveStep = sineWaveLength/360;
var cosineWaveStep = cosineWaveLength/360;
var angle = 0;
View gist:733263
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance Title="Portfolios"
OnQuickLaunch="TRUE"
TemplateType="10001"
FeatureId="59abaf93-f315-4c64-a7e3-e6402e05191c"
Url="Lists/Portfolios"
Description="List containing the available project portfolios">
<Data>
<Rows>
View gist:672570
// A user with the privileges / ability to ...
// - upload a file to a single document library
// - edit one shared page, to add a silverlight webpart
// - lure an administrator to visit said page
// .. can, using this Silverlight app, steal all (document library) files on
// the SharePoint server, and post them to some nasty location.
var q = new CamlQuery { ViewXml = "<View Scope='Recursive'/>" };
IEnumerable<List> lists =
ClientContext.Current.LoadQuery(
View gist:653358
class Program
{
static void Main(string[] args)
{
Console.Out.WriteLine("Baking cookies");
BakeCookies();
Console.Out.WriteLine("Cookies baked");
Console.ReadLine();
}
View gist:653306
string xml = @"
<root xmlns='http://www.w3.org/TR/html4/' xmlns:h='http://www.w3.org/TR/html4/' xmlns:f='http://www.w3schools.com/furniture'>
<h:table><h:tr><h:td>Apples</h:td><h:td>Bananas</h:td></h:tr></h:table><f:table><f:name>African Coffee Table</f:name>
<f:width>80</f:width><f:length>120</f:length></f:table></root>";
XElement x = XElement.Parse(xml);
(from node in x.DescendantsAndSelf()
where node is XElement
from attr in node.Attributes()
where attr.IsNamespaceDeclaration && attr.Name.LocalName == "xmlns"
select attr).All(attr => { attr.Remove(); return true; });
View gist:640422
var mock = new Mock<MemoryStream>();
mock
.Setup(x => x.Read(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback((byte[] array, int offset, int length) => Console.Out.WriteLine(array == null));
mock.Object.Read(new byte[1], 1, 2);
You can’t perform that action at this time.