Skip to content

Instantly share code, notes, and snippets.

@subhaze
subhaze / index.js
Last active November 29, 2018 15:08
Azure function to update IP on Cloudflare DNS; Usefull for DSM DDNS updates.
// URL set in Synology would look something like this:
// https://<YOUR_SUB_DOMAIN>.azurewebsites.net/api/HttpTriggerJS1?hostname=__HOSTNAME__&ip=__MYIP__&zoneid=__USERNAME__&key=__PASSWORD__&email=<YOUR_CF_EMAIL_LOGIN>&dnsidentifier=<YOUR_DNS_ID_FROM_CF>&recordtype=A
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var http = require('https');
var hostname = req.query.hostname;
var ip = req.query.ip;
var zoneid = req.query.zoneid;
@luizwbr
luizwbr / nodejs_java_encrypt_decrypt_128.js
Last active January 17, 2023 07:49
Encrypt and Decrypt using 128 for Nodejs or Javascript that actually works
// None of the tutorals could help me, so I adapted a few codes.
// What I really want is make a full duplex way between NodeJS and Java, using encrypt/decrypt with AES 128 bit
// 1 - you must have to generate the key
openssl enc -aes-128-cbc -k secret -P -md sha1
// key examples:
// DCDD74627CD60252E35DFBA91A4556AA
// 2CB24CFDB3F2520A5809EB4851168162
// 468CA14CA44C82B8264F61D42E0E9FA1
@Ravenstine
Ravenstine / aws-couchdb-setup.md
Last active April 19, 2024 15:03
Fast CouchDB setup in AWS

Fast CouchDB setup in AWS

CouchDB is a NoSQL database for storing JSON documents. It comes with a REST API out of the box so your client applications can persist data while requiring you to write little or no server-side code. CouchDB's killer feature is its ability to easily replicate, which allows for horizontal scaling, easy backup, and for client adapters to synchronize documents. This is perfect if you want to write an application that is offline-first. It's become my go-to database when creating new

@umidjons
umidjons / aes-256-cbc-nodejs-crypto.md
Last active March 13, 2022 07:12
AES-256-CBC example in Node.js using crypto module

AES-256-CBC example in Node.js using crypto module

'use strict';
const crypto = require('crypto');

// get password's md5 hash
let password = 'test';
let password_hash = crypto.createHash('md5').update(password, 'utf-8').digest('hex').toUpperCase();
console.log('key=', password_hash); // 098F6BCD4621D373CADE4E832627B4F6
@vlucas
vlucas / encryption.js
Last active July 23, 2024 01:24
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);
@moonmilk
moonmilk / README.md
Last active November 29, 2023 01:48
manually authorize a twitter app to a twitter account

So you're writting a twitterbot and you need to authorize your application to post to the account. You need an access token and secret for the account you're posting to. If the posting account is the same account that owns the application, no problem, you just push the button on your application's settings page to make the keys. But if you want to post to a different twitter account, there's no UI on apps.twitter.com to authorize it. So I made this bare-minimum node server to run through the authorization process. There's probably a much better way to do this, so please let me know what that way is!

ignore this and go down to the comments for better solutions

  • You'll need a server with node.js!
  • Make sure your application has a callback URL specified in its settings page, even if it's just a placeholder. If there's nothing in the callback URL slot, this method of authorization won't work.
  • In authorize.js, fill in your application's consumer key and secret, and the domain on which you'll be running th
@yoavniran
yoavniran / simple-nodejs-iv-encrypt-decrypt.js
Last active January 20, 2022 08:16
nodejs crypto - simple encrypt & decrypt using IV (Initialization Vector)
"use strict";
var crypto = require("crypto");
var EncryptionHelper = (function () {
function getKeyAndIV(key, callback) {
crypto.pseudoRandomBytes(16, function (err, ivBuffer) {
var keyBuffer = (key instanceof Buffer) ? key : new Buffer(key) ;
@subhaze
subhaze / custom-grid.scss
Last active August 29, 2015 14:06
So... I had to deal with a site that was original based on 16 cols, but, ended up with a few pages that were a mixture of 16 and 12 col layouts...
//Bootstrap 3 grid inception
@mixin new-grid($class, $columns, $grid-gutter-width: $grid-gutter-width){
$i: 1;
$grid-columns: $columns;
@include make-grid-columns($i: 1, $list: ".col-#{$class}-xs-#{$i}, .col-#{$class}-sm-#{$i}, .col-#{$class}-md-#{$i}, .col-#{$class}-lg-#{$i}");
@include make-grid(#{$class}-xs);
@media (min-width: $screen-sm-min) {
@include make-grid(#{$class}-sm);
}
@subhaze
subhaze / jQuery-tap.js
Last active January 23, 2019 16:00
Probably a more sane way to do this, but, here's a x-device click/tap event; It works with event delegation as well.
jQuery.event.special.tap = {
add: function(handleObj){
var $this = $(this);
var touchMoved = false;
var touched = false;
var touchesHandler = function(e){
if(e.type === 'touchstart'){
touchMoved = false;
touched = true;
}else if(e.type === 'touchmove'){
@zakjan
zakjan / cryptoHelpers.coffee
Last active June 26, 2021 08:29
Encryption in NodeJS
###*
* Encryption:
*
* cipher: AES-128-CBC
* key: 16 bytes
* IV: 16 bytes, random, non-reused, prepended to cipher text
* padding: PKCS#7
###
crypto = require 'crypto'