Skip to content

Instantly share code, notes, and snippets.

@iancrowther
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iancrowther/2bfb51b48b4a246e5fba to your computer and use it in GitHub Desktop.
Save iancrowther/2bfb51b48b4a246e5fba to your computer and use it in GitHub Desktop.
A collection of technology tips

A collection of technology tips

Proxy

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so

LoadModule rewrite_module modules/mod_rewrite.so

ProxyRequests Off

<Proxy *>
    Order allow,deny
    Allow from all
</Proxy>

ReWriteEngine on

ProxyPass     /x/server http://dev-int.x.tv:9080
ProxyPassReverse /x/server http://dev-int.x.tv:9080
ReWriteRule ^/x/server(.*) http://dev-int.x.tv:9080$1 [P]

create file and add test

$ cat > filename
This is some text that I want in this file
^D

http://www.codecoffee.com/tipsforlinux/articles2/042.html

open cwd

open .

Use cursor in output

$ cat [filename] | less

Keep service alive after term closed

$ nohup [cmd]

Keep service alive after term closed and no log files

$ nohup $COMMAND &>/dev/null &

lists open ports osx

$lsof -Pan -iTCP -sTCP:LISTEN

list global modules on top level only

$ npm ls -g --depth=0

List background jobs

$ jobs 

Bring forward the most recent background task

$ fg

eg. npm run docs & npm run docs-server & redis-server & npm run start & fg

Set npm registry(currently nodejitsu)

$ --registry=http://registry.npmjs.org/ --verbose
curl -XPUT -H "Authorization: Bearer $ACCESS_TOKEN" -d '{"code":"A5","part":["PCB","Tank NTC","Harness - main"],"applianceApplicability":"Highflow 440 & 550 only","description":"Tank NTC o/c"}' localhost:9000/fault-code
curl -XPUT -H "Authorization: Bearer $ACCESS_TOKEN" -H "Content-Type: application/json" -d '{"code":"A5","part":["PCB","Tank NTC","Harness - main"],"applianceApplicability":"Highflow 440 & 550 only","description":"Tank NTC o/c"}' localhost:9000/fault-code
curl -H "Authorization: Bearer $ACCESS_TOKEN" localhost:9000/fault-code/A5

Architecture

  • Each node has a health check
  • No loading order dependency
  • Keep docker configure outside of container
  • Data external
  • End to end principe, keep terminal is dumb like tcp

Virtual Box

Add port forwarding rules to the boot2docker VM

boot2docker suspend
VBoxManage modifyvm boot2docker-vm --natpf1 "docker,tcp,127.0.0.1,2375,,2375"
VBoxManage modifyvm boot2docker-vm --natpf1 "ssh,tcp,127.0.0.1,2022,,22"
VBoxManage modifyvm boot2docker-vm --natpf1 "nginx,tcp,127.0.0.1,8080,,8080"
VBoxManage modifyvm boot2docker-vm --natpf1 "nginx-service,tcp,127.0.0.1,8081,,8081"
VBoxManage modifyvm boot2docker-vm --natpf1 "mongo,tcp,127.0.0.1,27017,,27017"
VBoxManage modifyvm boot2docker-vm --natpf1 "mongo-admin,tcp,127.0.0.1,28017,,28017"
VBoxManage modifyvm boot2docker-vm --natpf1 "rabbit,tcp,127.0.0.1,5672,,5672"
VBoxManage modifyvm boot2docker-vm --natpf1 "rabbit-admin,tcp,127.0.0.1,15672,,15672"
VBoxManage modifyvm boot2docker-vm --natpf1 "redis,tcp,127.0.0.1,6379,,6379"
VBoxManage modifyvm boot2docker-vm --natpf1 "mysql,tcp,127.0.0.1,3306,,3306"
boot2docker resume

mongo

Start container

docker run -d -p 27017:27017 --name mongodb dockerfile/mongodb

Connect to mongo

mongo

boot2docker

start docker

boot2docker start
```

run terminal on ubuntu image 
```
docker run -i -t ubuntu
```

get image from private registry
```
docker run registry.<private>.info:5000/couchbase-server
```
remove dead images
```
docker rm $(docker ps -aq)
```

build image
```
docker build -t vibrant/k_cookie .
```

run image with terminal
```
docker run -t -i vibrant/k_cookie /bin/bash
```

run and expose terminal with out trigering cmd
```
docker run -p 5000:5000 vibrant/k_cookie
docker exec -it k_cookie bash
```

Seach git logs

git grep -n console.log

Get Object name when looking to see if an object is an Array

Object.prototype.toString.call([]);

Generate random string

Math.random().toString(36).slice(2);

Latch

(function(context) {
 
  "use strict";
 
	context.Latch = Latch;
 
	function Latch(countdown, onComplete) {
		// The latch counts down to 0 and then calls onComplete().
		// The countdown can be shortcut by calling bust();
		this.count = function() {
			if(countdown < 1) return false;
			if(--countdown < 1) onComplete();
			return true;
		};
		this.bust = function() {
			countdown = 0;
			onComplete();
		};
	}
 
 
}(module.exports));

Loop through typeof Object

for (var key in p) {
  if (p.hasOwnProperty(key)) {
    alert(key + " -> " + p[key]);
  }
}

saucelabs

export JENKINS='true'
npm install
npm run webdriver:update
./node_modules/.bin/protractor test/saucelabs.conf.js

cuke2jade

npm install npm install cuke2jade npm install jade

export JENKINS='true'
export TAGS='@sprint-3,@sprint-2' 
export TEST_FORMAT='json' 
export NODEBIN=npm bin 
time curl https://stage-news.tes.co.uk >/dev/null 
npm -s run test:protractor | tee "test/report/index.json" | node $NODEBIN/cuke2jade --css css/bootstrap.css,css/app.css --header "Avengers - Sprint Progress" --progress | node $NODEBIN/jade > test/report/index.new.html; 
export PASSED=${PIPESTATUS} 
mv test/report/index.new.html test/report/index.html; 
test $PASSED -eq 0

Search

Exclude files or folders (cmd + shift + f)

In "Where:" enter the filenames or paths prefixed with a minus.

"Where:" -styles.css, -scripts.js

Build system

Less

{
  "shell" : true,
  "cmd": ["lessc <path>/less/bootstrap.less <path>/css/styles.css"]
}

Packages

{
	"extensions": ["less"]
}

Snippets

Save as .sublime-snippet

<snippet>
  <!-- put this file in /packages/User/<Folder Name>/console_log.sublime-snippet then restart your Sublime Text 3 -->
  <content><![CDATA[console.log($1);$0]]></content>
  <tabTrigger>cl</tabTrigger>
  <scope>text.html,source.js</scope>
  <description>console.log( '' );</description>
</snippet>
<snippet>
  <!-- put this in another file /packages/User/<Folder Name>/console_dir.sublime-snippet then restart your Sublime Text 3 -->
  <content><![CDATA[console.dir($1);$0]]></content>
  <tabTrigger>cd</tabTrigger>
  <scope>text.html,source.js</scope>
  <description>console.dir( '' );</description>
</snippet>
<snippet>
  <content><![CDATA[
if (err) { return console.error(err); }
]]></content>
  <tabTrigger>ce</tabTrigger>
  <scope>source.js</scope>
  <description>console.error( '' );</description>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment