Skip to content

Instantly share code, notes, and snippets.

/*
* media.matchMedium()- test whether a CSS media type or media query applies
* primary author: Scott Jehl
* Copyright (c) 2010 Filament Group, Inc
* MIT license
* adapted by Paul Irish to use the matchMedium API
* http://www.w3.org/TR/cssom-view/#media
* Doesn't implement media.type as there's no way for crossbrowser property
* getters. instead of media.type == 'tv' just use media.matchMedium('tv')
@switz
switz / phishNet.coffee
Created November 16, 2012 04:19
Client side and Server side request wrapper (used with DerbyJS)
# src/api/phishnet.coffee
API_KEY = 'removed'
API_URL = 'api.phish.net/api.js'
METHOD = 'pnet.shows.setlists.get'
API_FORMAT = 'json'
API_VERSION = '2.0'
Request = require '../lib/request'
@enjalot
enjalot / hook.coffee
Last active December 20, 2015 05:58
derby server side hooks (to hold you over for now)
#make a hook
store.hook 'change', 'collection.*.foo', (docId, value, op, session, backend) ->
model = store.createModel()
#logic
#setup the hook method
store.hook = (method, pattern, fn) ->
store.shareClient.use 'after submit', (shareRequest, next) ->
{opData} = shareRequest
@guifromrio
guifromrio / nodejs-ubuntu-bind-port-80.md
Last active June 25, 2024 10:30
Allow Node.js to bind to privileged ports without root access on Ubuntu

How to: Allow Node to bind to port 80 without sudo

TL;DR

Only do this if you understand the consequences: all node programs will be able to bind on ports < 1024

sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/node

Important: your node location may vary. Use which node to find it, or use it directly in the command:

@joeyAghion
joeyAghion / mongodb_collection_sizes.js
Last active May 23, 2024 15:30
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
ALLOWED_COLLECTIONS = [
'auths' # Private user data
]
store.allow 'create', 'auths', (docId, newDoc, session) ->
console.log '[Auths] CREATE'
undefined
store.allow 'all', 'auths.*', (docId, relPath, opData, docBeingUpdated, session) ->
console.log '[Auths] CHANGE'
@nateps
nateps / gist:02d0b0293880905476bd
Created July 12, 2014 00:45
Example ShareJS access control middleware for use with Derby
# Whitelist collections
ALLOW_COLLECTIONS = {
'accounts': true
'users': true
}
module.exports = (shareClient) ->
# Hold on to session object for later use. The HTTP req object is only
# available in the connect event
shareClient.use 'connect', (shareRequest, next) ->
upstream nodejs {
server 127.0.0.1:3000;
keepalive 8;
}
server {
listen 80;
listen [::]:80 ipv6only=on default_server;
server_name mydomain.fi;
@vlucas
vlucas / encryption.js
Last active July 11, 2024 22:13
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
@antony
antony / SimpleFileUploader.svelte
Created September 18, 2019 16:03
File Uploader Svelte
<label>
{#if uploading}
<Progress bind:percent={progress} text="Uploading..." />
{:else if processing}
<Progress percent={100} text="Processing..." />
{:else}
<slot name="content">
</slot>
{/if}
<input