Skip to content

Instantly share code, notes, and snippets.

@conradz
conradz / gist:7686821
Created November 28, 2013 03:21
rework-npm

rework-npm

I recently published rework-npm that allows you to import CSS files using the same rules that the Node.js uses for modules. This lets you install and manage CSS packages using npm the same way you manage JS modules.

Why npm?

First of all, why use npm? Why does it make sense to use npm for CSS? Npm is good for a number of reasons.

First, it is simple to use. Want to publish a module? Just use npm publish. Want to install a new package and save it to the dependencies? Just use npm install --save mymodule. This makes it super easy to create and maintain small modules, instead of putting everything into one large module.

@conradz
conradz / delay.md
Created April 5, 2013 20:16
Global Delay State

Since thinking more on the function/delay implementation, I've come to the conclusion that it basically is unusable in many cases when it caches functions globally.

Simple Example

function Item(el) {
  this.el = el;
}

Item.prototype.resize = function(width, height) {
@conradz
conradz / credentials.js
Created September 26, 2012 21:04
Windows 8 User Credentials
var CREDENTIAL_NAME = "<Your Credential Resource Name>";
var signin = new WinJS.Promise(function (comp, err) {
var vault = new Windows.Security.Credentials.PasswordVault();
try {
var stored = vault.findAllByResource(CREDENTIAL_NAME);
if (stored.length > 0) {
stored = stored[0];
@conradz
conradz / module.js
Created September 19, 2012 11:07 — forked from ded/module.js
!function (name, definition) {
if (typeof define == 'function' && define.amd) define(name, definition)
else if (typeof module != 'undefined') module.exports = definition()
else this[name] = definition()
}('thing', function () {
// codes
return module
})
@conradz
conradz / gist:3749059
Created September 19, 2012 11:03
Sublime Text 2 - Useful Shortcuts
h1. Sublime Text 2 - Useful Shortcuts (PC)
Loosely ordered with the commands I use most towards the top. Sublime also offer "full documentation":http://www.sublimetext.com/docs/2/.
h2. Editing
| *Ctrl+C* | copy current line (if no selection) |
| *Ctrl+X* | cut current line (if no selection) |
| *Ctrl+⇧+K*| delete line |
| *Ctrl+↩* | insert line after |
@conradz
conradz / handler.cs
Created September 10, 2012 21:25
Use custom server for Fleck websockets
// In the HTTP handler method:
WebSocketConnection connection = null;
connection = new WebSocketConnection(
new SocketWrapper(response.Socket),
Accept,
b => MapRequest(request), // Creates the `WebSocketHttpRequest` from my `request` object
r => HandlerFactory.BuildHandler(
r,
s => connection.OnMessage(s),
() => connection.Close(),
@conradz
conradz / Makefile
Created June 20, 2012 20:15
Makefile for simple C app
SOURCES=main.c
EXECUTABLE=app.exe
CC=gcc
LDFLAGS=-static
CFLAGS=-c -Wall
OBJECTS=$(SOURCES:.c=.o)
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
@conradz
conradz / output.txt
Created February 24, 2012 19:35
rubinius build failure
Conrad@Conrad-PC ~
$ ruby -v
ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
Conrad@Conrad-PC ~
$ rake -V
rake, version 0.9.2.2
Conrad@Conrad-PC ~
@conradz
conradz / testnet.js
Created September 28, 2011 20:45
Node TCP Test
var net = require('net');
var host = '127.0.0.1';
var port = 8888;
var server = net.createServer(function(client) {
console.log('Client connected');
client.on('data', function(data) {
client.write(data);
});
@conradz
conradz / test.js
Created September 27, 2011 19:49
Node HTTP Server Test
var http = require('http');
var port = 1337;
var host = 'localhost';
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
});
server.listen(port, host);