Skip to content

Instantly share code, notes, and snippets.

View cbrunnkvist's full-sized avatar

Conny Brunnkvist cbrunnkvist

View GitHub Profile
@cbrunnkvist
cbrunnkvist / avg_with_reduce.js
Last active July 26, 2022 13:52 — forked from ekrem-aktas/avg_with_reduce.js
the complexity comes from relying on a complex accumulator object instead just returning the average number ;)
const basket = [
{ name:"apple", type: "fruit", calories: 52 },
{ name:"broccoli", type: "vegetable", calories: 45 },
{ name:"banana", type: "fruit", calories: 89 }
];
class CaloriesAccumulator {
constructor(fruitCount = 0, avgCalories = 0) {
console.debug(`count: ${fruitCount}\tavg: ${avgCalories}`)
this.fruitCount = fruitCount
@cbrunnkvist
cbrunnkvist / example1.sh
Last active October 31, 2019 13:04 — forked from rbraband/example 1
Howto implement stored procedures within Redis (-with enable_strict_lua)
# Step 0 -- create test data
redis-cli HSET :object:30343552:data foo bar
# Step 1 -- store sample function 'sampleFunction'
redis-cli SET :functions:sample1 "
redis.call('SELECT', 0);
local data = redis.call('HGETALL', ':object:' .. ARGV[1] .. ':data');
return table.concat(data, '+');
"
@cbrunnkvist
cbrunnkvist / .bash_profile
Last active February 13, 2024 01:40 — forked from burpnoes/.bash_profile
Bash git prompt and command completion with Xcode / Mac OS X >= Mavericks (no Homebrew required)
if [ -f /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash ]; then
. /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
fi
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
# configuration variables as documented in:
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh#L8
#
GIT_PS1_SHOWDIRTYSTATE="yes"
var FooPrototype = {
methodA: function methodA() {},
methodB: function methodB() {},
methodC: function methodC() {}
};
exports.createFoo = function() {
return Object.create(FooPrototype);
};