Skip to content

Instantly share code, notes, and snippets.

@rd13
rd13 / setup.js
Created July 7, 2023 10:55
js test
const array = [...new Array(10000,)].map((_,i) => i);
@rd13
rd13 / iso8601_duration.js
Last active October 15, 2021 13:40
Encode an iso8601 duration in Javascript
/**
* Utility function to convert seconds to an iso8601 duration string.
*
* @param seconds int The number of seconds to encode.
* @return string iso8601 formatted duration
*/
const iso8601Duration = (seconds = 0) => {
let _seconds = seconds;
@rd13
rd13 / .zshrc
Created November 13, 2018 15:40
JIRA / GIT branch opener / alias
alias jira='open "http://jira-host.com/browse/$(git rev-parse --abbrev-ref HEAD)"'
@rd13
rd13 / package.json
Created October 25, 2018 12:39
npm script to pass multiple files through uglifyjs
{
"scripts": {
"compress:js:components": "find dist/components/*.js -type f -exec basename {} .js \\; | xargs -I '{}' uglifyjs --compress --mangle --output dist/components/{}.min.js -- dist/components/{}.js",
}
}
@rd13
rd13 / cartesian.js
Created April 25, 2018 18:31
Javascript cartesian product (power set) using bits
const input = 'abc'
const inputLength = 3
const powerSetSize = Math.pow(2, inputLength)
let result = []
for (let k = 0; k < powerSetSize; k++) {
let set = "";
let binaryDigits = k;
for (let j = 0; j < inputLength; j++) {
@rd13
rd13 / .swift
Last active September 11, 2022 17:00
Copy database file from bundle to documents in Swift 3
func copyDatabaseIfNeeded() {
// Move database file from bundle to documents folder
let fileManager = FileManager.default
let documentsUrl = fileManager.urls(for: .documentDirectory,
in: .userDomainMask)
guard documentsUrl.count != 0 else {
return // Could not find documents URL
@rd13
rd13 / draggable.coffee
Created October 3, 2014 09:43
Angular Draggable Directive
'use strict'
angular.module('ip')
.directive('draggable', ($document) ->
restrict: "EA"
link: (scope, element, attr) ->
pos_y = pos_x = drg_h = drg_w = 0
@rd13
rd13 / gist:f1c01c42b18b9e358223
Created March 26, 2014 22:20
Enigma C++ Perf
#include <iostream>
#include <cstring>
#include <array>
using namespace std;
const std::array<char, 27> alpha = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
const std::array<std::array<char, 27>, 3> rotors
{
{{"EKMFLGDQVZNTOWYHXUSPAIBRCJ"},
{"AJDKSIRUXBLHWTMCQGZNPYFVOE"},
@rd13
rd13 / gist:7372358
Created November 8, 2013 15:11
Enigma Perl
#!/usr/bin/perl
$|=1; #disable output buffering, this is necessary for proper output through pipe
my @rotors = ('EKMFLGDQVZNTOWYHXUSPAIBRCJ','AJDKSIRUXBLHWTMCQGZNPYFVOE','BDFHJLCPRTXVZNYEIWGAKMUSQO');
my $reflector = "YRUHQSLDPXNGOKMIEBFZCWVJAT";
my $key = "ABC";
sub li {
@rd13
rd13 / gist:7372334
Created November 8, 2013 15:09
Enigma Python
#!/usr/bin/env python
import string
_rotors = [ 'EKMFLGDQVZNTOWYHXUSPAIBRCJ',
'AJDKSIRUXBLHWTMCQGZNPYFVOE',
'BDFHJLCPRTXVZNYEIWGAKMUSQO'
]
_reflector = "YRUHQSLDPXNGOKMIEBFZCWVJAT"
_key = "ABC"