Skip to content

Instantly share code, notes, and snippets.

View NiCkEl5's full-sized avatar

Jaime Labra NiCkEl5

  • NiCkEl Solutions
  • Barcelona, Spain
View GitHub Profile
@hannesl
hannesl / my_controller_test.rb
Created September 8, 2016 10:50
Testing http basic authentication in Rails 5
class MyControllerTest < ActionDispatch::IntegrationTest
test "authentication" do
params = {test: "object"}
auth_headers = {"Authorization" => "Basic #{Base64.encode64('test:test')}"}
post '/my-controller', params: params, as: :json
assert_response 401
post '/my-controller', params: params, as: :json, headers: auth_headers
assert_response :success
end
@vlucas
vlucas / encryption.ts
Last active May 8, 2025 12:51
Stronger Encryption and Decryption in Node.js
import { createCipheriv, createDecipheriv, randomBytes } from "crypto";
const ENCRYPTION_KEY: string = process.env.ENCRYPTION_KEY || ""; // Must be 256 bits (32 characters)
const IV_LENGTH: number = 16; // For AES, this is always 16
/**
* Will generate valid encryption keys for use
* Not used in the code below, but generate one and store it in ENV for your own purposes
*/
export function keyGen() {
@andrei-tofan
andrei-tofan / example.js
Last active February 29, 2024 23:59
node.js writable buffer stream (pdfkit example)
/**
* Convert PDFDocument to Base64
*/
const PDFDocument = require('pdfkit');
const stream = require('./stream');
// crate document and write stream
let doc = new PDFDocument();
let writeStream = new stream.WritableBufferStream();