Skip to content

Instantly share code, notes, and snippets.

@AlexanderBrevigSublime
AlexanderBrevigSublime / gist:3814257
Created October 1, 2012 20:35
JavaScript: Class simulation
/// Make this script available somewhere
var extendsClass = this.extendsClass || function (d, b) {
function __inheritedProto() { this.constructor = d; }
__inheritedProto.prototype = b.prototype;
d.prototype = new __inheritedProto();
}
/// Sample class 1
var CLASS = (function() {
function CLASS(data) {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace System.Linq
{
public static class IEnumerableExtensionForEach
{
public static void ForEach<T>(this IEnumerable<T> list, Action<T> block) {
@AlexanderBrevigSublime
AlexanderBrevigSublime / gist:3810624
Created October 1, 2012 09:51
Java: Thread safe singleton
class YourSingletonClass {
public static synchronized YourSingletonClass getInstance() {
if (instance == null) {
instance = new YourSingletonClass();
}
return instance;
}
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
@AlexanderBrevigSublime
AlexanderBrevigSublime / gist:3810617
Created October 1, 2012 09:51
Python: Minimal safe module
#!/usr/bin/python
import sys
def main():
print 'Hello there', sys.argv[1]
if __name__ == '__main__':
main()
@AlexanderBrevigSublime
AlexanderBrevigSublime / gist:3810615
Created October 1, 2012 09:50
HTML: Socket.io client
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('channel1', function (data) {
console.log(data);
socket.emit('channel2', { other: 'message' });
});
</script>
@AlexanderBrevigSublime
AlexanderBrevigSublime / gist:3810613
Created October 1, 2012 09:50
Node.js: Socket.io server
var io = require('socket.io').listen(process.env.PORT || 80);
io.sockets.on('connection', function (socket) {
socket.emit('channel1', { data: 'value' });
socket.on('channel2', function (data) {
console.log(data);
});
});
@AlexanderBrevigSublime
AlexanderBrevigSublime / gist:3810612
Created October 1, 2012 09:49
JavaScript: Minimal w/namespace
var NAMESPACE = NAMESPACE = NAMESPACE || {};
@AlexanderBrevigSublime
AlexanderBrevigSublime / gist:3810610
Created October 1, 2012 09:48
C++: Minimal main
#include <iostream>
int main()
{
std::cout << "Implement me!" << std::endl;
return 0;
}
@AlexanderBrevigSublime
AlexanderBrevigSublime / gist:3810608
Created October 1, 2012 09:48
Wiring: New sketch
/*
Description
*/
void setup()
{
}
void loop()
{
@AlexanderBrevigSublime
AlexanderBrevigSublime / gist:3810606
Created October 1, 2012 09:48
HTML: Boilerplate w/jQuery
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="" type="text/css">
<meta charset=utf-8 />
<title></title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>