Skip to content

Instantly share code, notes, and snippets.

View coder36's full-sized avatar

Mark Middleton coder36

  • Newcastle
View GitHub Profile
@coder36
coder36 / set_up_kubernates_cluster
Last active March 3, 2018 12:07
Set up a kubernates cluster on Virtualbox
# Setting up a kubernetes cluster on Virtual Box
## Server/Node setup
### Install ubuntu 16.04
Login as root using
```
sudo su -
```
@coder36
coder36 / apex random string
Created September 25, 2017 16:59
Apex random string generator
trigger ContactGuidGenerator on Contact (before insert) {
for( Contact c: Trigger.new ) {
final String chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
String guid = '';
while (guid.length() < 16) {
Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length());
guid += chars.substring(idx, idx+1);
}
c.guid__c = guid;
@coder36
coder36 / ContactGuidGenerator
Created September 25, 2017 16:49
Apex Guid generator
trigger ContactGuidGenerator on Contact (before insert) {
for( Contact c: Trigger.new ) {
Blob b = Crypto.GenerateAESKey(128);
String h = EncodingUtil.ConvertTohex(b);
String guid = h.SubString(0,8)+ h.SubString(8,12) + h.SubString(12,16) + h.SubString(16,20) + h.substring(20);
c.guid__c = guid;
// guid should be Text, size 32
}
}
@coder36
coder36 / jest_test.js
Created October 10, 2016 12:58
Jest and mocking
import React from 'react';
import ReactDOM from 'react-dom';
import { mount } from 'enzyme'
import ReactTestUtils from 'react-addons-test-utils'
import * as api from './api';
it('renders without crashing', () => {
api.sayHello = jest.fn()
api.sayHello.mockImplementation( (x) => "boom" )
import sinonStubPromise from 'sinon-stub-promise';
import sinon from 'sinon'
sinonStubPromise(sinon)
let stubedFetch = sinon.stub(window, 'fetch') )
window.fetch.returns(Promise.resolve(mockApiResponse()));
function mockApiResponse(body = {}) {
@coder36
coder36 / maven_compiler_plugin_xm
Created December 18, 2015 10:46
Maven compiler plugin XML
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
@coder36
coder36 / find_nested_prop.js
Created October 8, 2015 22:22
Search deeply nested javascript object for property
function find_nested_prop( obj, propName, callback ) {
for( var key in obj ) {
var val = obj[key]
if ( key === propName ) {
callback(val, obj)
}
else if ( typeof val === 'object' ) {

git log --graph --all --decorate --pretty --oneline

@coder36
coder36 / gist:eb775638aad9a3aec37e
Created May 3, 2015 23:25
Simple Ruby webserver
ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd).start'
@coder36
coder36 / gist:49e1eb5968ecfff1453c
Last active August 29, 2015 14:17
Capybara command line demo
gem install capybara
gem install selenium-webkit
irb
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end