Skip to content

Instantly share code, notes, and snippets.

View simonneutert's full-sized avatar
🌻
'); DROP TABLE tanks;--

Simon Neutert simonneutert

🌻
'); DROP TABLE tanks;--
View GitHub Profile
@simonneutert
simonneutert / towers_of_hanoi.clj
Created October 1, 2022 17:14
Towers of Hanoi in Clojure
(defn hanoi [n left middle right]
(cond
(> n 5) (throw (Exception. "No way! This would run far too long!"))
(= n 1) (println "Move disc" n "from" left "to" right)
:else (do (hanoi (dec n) left right middle)
(println "Move disc" n "from" left "to" right)
(hanoi (dec n) middle left right))))
(hanoi 5 :left :middle :right)
@simonneutert
simonneutert / color.lighten.js
Created January 11, 2022 19:13 — forked from renancouto/color.lighten.js
Method to lighten / darken hex colors using Javascript.
var LightenColor = function(color, percent) {
var num = parseInt(color,16),
amt = Math.round(2.55 * percent),
R = (num >> 16) + amt,
B = (num >> 8 & 0x00FF) + amt,
G = (num & 0x0000FF) + amt;
return (0x1000000 + (R<255?R<1?0:R:255)*0x10000 + (B<255?B<1?0:B:255)*0x100 + (G<255?G<1?0:G:255)).toString(16).slice(1);
};
@simonneutert
simonneutert / formatObjectGUID.js
Created June 7, 2021 14:58
format objectGUID
// source: https://github.com/ldapjs/node-ldapjs/issues/297#issuecomment-137765214
const formatGUID = function (objectGUID) {
var data = Buffer.from(objectGUID, 'binary');
// GUID_FORMAT_D
var template = '{3}{2}{1}{0}-{5}{4}-{7}{6}-{8}{9}-{10}{11}{12}{13}{14}{15}';
// check each byte
for (var i = 0; i < data.length; i++) {
@simonneutert
simonneutert / sid.js
Created June 7, 2021 14:56 — forked from Krizzzn/sid.js
Convert binary buffer object SID to string
/*
# Convert binary encoded object SID to a string
# (eg. S-1-5-21-1004336348-1177238915-682003330-512)
#
# SID format: https://technet.microsoft.com/en-us/library/cc962011.aspx
#
# ldapjs `searchEntry` has attribute `raw` that holds the raw
# values, including the `objectSid` buffer when one exists. Pass that
# buffer to get the string representation that can then be easily
# used in LDAP search filters, for example.
@simonneutert
simonneutert / Hex Color to rgba.js
Created April 15, 2021 09:15 — forked from danieliser/es5.js
Convert Hex Color to rgba with opacity
/**
* ECMA2015
*/
function convertHex(hexCode,opacity){
var hex = hexCode.replace('#','');
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
@simonneutert
simonneutert / einstein.pl
Created May 19, 2017 08:39 — forked from jgilchrist/einstein.pl
A Prolog solution to Einstein's Riddle
right_of(X, Y) :- X is Y+1.
left_of(X, Y) :- right_of(Y, X).
next_to(X, Y) :- right_of(X, Y).
next_to(X, Y) :- left_of(X, Y).
solution(Street, FishOwner) :-
Street = [
house(1, Nationality1, Color1, Pet1, Drinks1, Smokes1),
house(2, Nationality2, Color2, Pet2, Drinks2, Smokes2),