Skip to content

Instantly share code, notes, and snippets.

View drblue's full-sized avatar
🔥
All Your Memes Are Belong To Me

Johan Nordström drblue

🔥
All Your Memes Are Belong To Me
View GitHub Profile
@drblue
drblue / .bashrc
Created November 15, 2022 14:32
Git-prompt for bash
function git-branch-name {
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
}
function git-branch-prompt {
local branch=`git-branch-name`
if [ $branch ]; then printf " [%s]" $branch; fi
}
PS1="\u@\h \[\033[0;36m\]\w\[\033[0m\]\[\033[0;32m\]\$(git-branch-prompt)\[\033[0m\] \$ "
@drblue
drblue / products.js
Created March 29, 2022 09:13
Array reduce + map
const products = [
{ name: "Product 1", price: 42 },
{ name: "Product 2", price: 20 },
{ name: "Product 3", price: 1337 },
];
const totalValue = products
.filter(product => product.price > 30)
.reduce( (sum, product) => {
return sum + product.price
@drblue
drblue / classes.js
Last active March 29, 2022 08:54
Classes in JavaScript
class Rectangle {
constructor(rooms, jacuzzi, solarPanels = true) {
if (typeof height !== "number") {
throw new Error("Height is not a number")
}
this.height = height
this.width = width
}
area() {
@drblue
drblue / class.MyWidgetSkeleton.php
Last active June 17, 2021 08:00
A skeleton of a widget.
<?php
class MyWidgetSkeleton extends WP_Widget {
/**
* Construct a new widget instance.
*/
public function __construct() {
parent::__construct(
'my-widget-skeleton', // Base ID
@drblue
drblue / http.js
Created April 6, 2020 15:28
node.js http server example
/**
* http
*/
const http = require('http');
const server = http.createServer();
server.on('request', function (req, res) {
// code here
res.writeHead(200, {
'Content-Type': 'text/html',
@drblue
drblue / events.js
Created April 6, 2020 15:12
node.js event emitter demo (es6)
/**
* events
*/
const events = require('events');
class Person extends events.EventEmitter{
constructor(name){
super();
this.name = name;
}
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//

Keybase proof

I hereby claim:

  • I am drblue on github.
  • I am dr_blue (https://keybase.io/dr_blue) on keybase.
  • I have a public key ASCKkpIa863N8bf1ZF_o_gLedB3ii5VYUhnRkFZ5fgzqOgo

To claim this, I am signing this object:

@drblue
drblue / class.StarWarsWidget.php
Created May 22, 2019 13:02
Empty StarWars Widget
<?php
/**
* Adds StarWarsWidget widget.
*/
class StarWarsWidget extends WP_Widget {
/**
* Register widget with WordPress.
@drblue
drblue / sphp.sh
Created April 28, 2019 21:31 — forked from rhukster/sphp.sh
#!/bin/bash
# Creator: Phil Cook
# Modified: Andy Miller
brew_prefix=$(brew --prefix | sed 's#/#\\\/#g')
brew_array=("5.5","5.6","7.0","7.1","7.2", "7.3")
php_array=("php@5.5" "php@5.6" "php@7.0" "php@7.1" "php@7.2" "php@7.3")
valet_support_php_version_array=("php@5.5" "php@5.6" "php@7.0" "php@7.1" "php@7.2" "php@7.3")
php_installed_array=()
php_version="php@$1"