Skip to content

Instantly share code, notes, and snippets.

@msramalho
msramalho / Cryptography.java
Created January 13, 2020 22:59
Java Class to manage cryptography keys in Android Keystore using "AES/CBC/PKCS7Padding" - encrypt and decrypt strings
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.util.Base64;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@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
@vlucas
vlucas / encryption.js
Last active March 28, 2024 17:36
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);
upstream nodejs {
server 127.0.0.1:3000;
keepalive 8;
}
server {
listen 80;
listen [::]:80 ipv6only=on default_server;
server_name mydomain.fi;
@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) ->
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'
@joeyAghion
joeyAghion / mongodb_collection_sizes.js
Last active February 9, 2024 22:37
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'] + ")"); }
@guifromrio
guifromrio / nodejs-ubuntu-bind-port-80.md
Last active January 10, 2024 22:47
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:

@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
@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'