Skip to content

Instantly share code, notes, and snippets.

View aredridel's full-sized avatar
💭
See my social media for status.

Aria Stewart aredridel

💭
See my social media for status.
View GitHub Profile
Proposed API for HTML5 parser in Javascript
var HTML5 = require('html5')
HTML5.parse(string, [{DOM: domModule}]) -> DOM objects
new HTML5.Parser(source, [{DOM: domModule}]) -> eventEmitter with "document" property. emits "end" when fully parsed, and the document property is a DOM tree
Internal:
buffer = new Buffer(1024 * 1024);
buffer.readFrom(socketA);
buffer.writeTo(socketB);
... is this sys.pump, with a one megabyte buffer?
Make write throw an error when it would block (making sure people handle writes in the wouldblock case, not blocking nor throwing data away)
Make an enlargeable buffer for cases where you want the old growing-memory behavior of write()
@aredridel
aredridel / upload.js
Created December 19, 2010 04:25
Form file upload
var http = require('http')
var cl = http.createClient(80, 'dinhe.net');
var req = cl.request('POST', '/~aredridel/t.php',
{ host: 'dinhe.net', 'Content-Type': 'multipart/form-data; boundary=----asd123' })
req.write('------asd123\r\nContent-Disposition: form-data; name="file"; filename="test.txt"\r\nContent-Type: application/octet-stream\r\n\r\n')
req.write("Testing 123\r\n")
req.write("------asd123--r\n")
req.end()
typetable = Account.reflections[@input.type.intern].table_name
@accounts = @accounts.joins(@input.type)
@accounts.where(Contact.p(:id)).where(
Arel::Nodes::Grouping.new @accounts = [:first, :last, :company, :name].inject(@accounts) { |a,e|
Arel::Nodes::Or.new(a, Contact.p(e).matches("%#{@input.q}%"))
})
@aredridel
aredridel / codePage.patch
Created January 1, 2011 23:12
Fix for code page error
Index: Classes/PHPExcel/Shared/CodePage.php
===================================================================
--- Classes/PHPExcel/Shared/CodePage.php (revision 66289)
+++ Classes/PHPExcel/Shared/CodePage.php (working copy)
@@ -45,6 +45,7 @@
*/
public static function NumberToName($codePage = '1252')
{
+ if($codePage == 0) $codePage = 1252;
switch ($codePage) {
@aredridel
aredridel / gist:774092
Created January 11, 2011 06:07
Exception inheritance from jsdom
core.DOMException = function(code, message) {
this._code = code;
Error.call(this, core.exceptionMessages[code]);
this.message = core.exceptionMessages[code];
if(message) this.message = this.message + ": " + message;
if(Error.captureStackTrace) Error.captureStackTrace(this, core.DOMException);
};
core.DOMException.prototype = {
get code() { return this._code;},
aredridel@host ~/working ls testsparse
-rw-r--r-- 1 aredridel users 1000000001 Apr 24 00:27 testsparse
aredridel@host ~/working$ stat testsparse
File: `testsparse'
Size: 1000000001 Blocks: 32 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 2408452 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/aredridel) Gid: ( 1000/ users)
Access: 2011-04-24 00:26:56.000000000 -0600
Modify: 2011-04-24 00:27:04.000000000 -0600
@aredridel
aredridel / reader.js
Created June 8, 2011 07:23
Read from a stream: works with a FIFO.
var fs = require('fs')
var s = fs.createReadStream('x')
s.on('data', function(b) { console.log(b) })
@aredridel
aredridel / Diagram.txt
Created September 4, 2011 03:48
Simple request/action/response and template example
Post
+-----+
| |
+-----------+-+ | +------------+
+--------------+ | | +-v------------+ | |
| | | Register | | | | Logged in |
| | | Template | | Do | | Template |
| Register | | | | Register | | |
| | | | | | | |
| | +-------^-----+ | | +--^---------+
@aredridel
aredridel / ifcfg-ppp0
Created October 28, 2011 02:17
PPP configuration for CentOS and PPPoA
# this file goes in /etc/sysconfig/networking/profiles/default
NAME=ppp0
BOOTPROTO=dhcp
TYPE=Modem
AC=off
BSDCOMP=off
VJCCOMP=off
CCP=off
PC=off
VJ=off