Skip to content

Instantly share code, notes, and snippets.

@rsolomo
rsolomo / class.js
Created October 25, 2016 22:44
new class vs new function prototype
function Foo1() {
}
Foo1.prototype.interact = function() {
this.dispose = true
}
class Foo2 {
interact() {
this.dispose = true
@rsolomo
rsolomo / gist:2d4e8c4c8d99fe7c0cdf
Created August 7, 2014 02:44
strange intermittent error
dgram.js:147
newHandle.lookup = self._handle.lookup;
^
TypeError: Cannot set property 'lookup' of undefined
at replaceHandle (dgram.js:147:20)
at dgram.js:201:9
at Object.10:8921 (cluster.js:592:5)
at handleResponse (cluster.js:171:41)
at respond (cluster.js:192:5)
at handleMessage (cluster.js:202:5)
@rsolomo
rsolomo / udp_listener.js
Created February 3, 2014 06:33
udp listener in node.js
var dgram = require('dgram')
var socket = dgram.createSocket('udp4')
socket.on('message', function(msg) {
console.log(msg.toString())
})
socket.bind(5514, '127.0.0.1')
@rsolomo
rsolomo / udp_listener.dart
Last active November 20, 2018 03:37
trying out a UDP listener in Dart
import 'dart:io';
void main() {
RawDatagramSocket.bind('127.0.0.1', 5514, reuseAddress: true).then((value) {
value.listen((event) {
if (event == RawSocketEvent.READ) {
var datagram = value.receive();
print(new String.fromCharCodes(datagram.data));
}
});
@rsolomo
rsolomo / udp_listener.rs
Last active July 15, 2022 14:19
trying out creating a udp listener in Rust
use std::io::net::ip;
use std::io::net::udp;
use std::str;
fn main() {
let addr = ip::SocketAddr {
ip: ip::Ipv4Addr(127, 0, 0, 1),
port: 5514
};
@rsolomo
rsolomo / set.js
Created July 31, 2013 23:45
strings only set example
// ECMA 5
var duplicates = ['taco', 'taco', 'bacon', 'pancake', 'cake', 'salt', 'cake']
var set = {}
duplicates.forEach(function(value) {
set[value] = true
})
console.log(Object.keys(set)) // Outputs an array with no duplicates
@rsolomo
rsolomo / gist:5889137
Created June 29, 2013 00:36
random javascript inheritance example
// Random inheritance example
function Vehicle(color) {
this.color = color
}
Vehicle.prototype.move = function() {
// Do some stuff here
}
@rsolomo
rsolomo / gist:5248993
Created March 26, 2013 20:36
Runs 'npm test' on save if a package.json is present in the current directory. I just have this as part of my vimrc.
if filereadable("package.json")
autocmd BufWritePost <buffer> !npm test
endif
@rsolomo
rsolomo / gist:4165828
Created November 29, 2012 00:26
Test showing that undefined is not an object
<!DOCTYPE html>
<html>
<head>
<title>Undefined Test</title>
<meta charset='utf-8' />
</head>
<body>
<script>
if (undefined instanceof Object) {
alert('undefined is an Object')
@rsolomo
rsolomo / nodejs.sh
Created November 6, 2012 02:29 — forked from crcastle/nodejs.sh
Node.js startup script for AWS EC2 Linux box
#!/bin/bash
# nodejs - Startup script for node.js server
# chkconfig: 35 85 15
# description: node is an event-based web server.
# processname: node
# server: /path/to/your/node/file.js
# pidfile: /var/run/nodejs.pid
#