Skip to content

Instantly share code, notes, and snippets.

View hapiben's full-sized avatar

Ben hapiben

View GitHub Profile
1) Setup Server on Vultr
Select “create New Server(e.g. 123.123.123.123)”, select “Ubuntu 14.04 LTS”
Once your server has been created, wait for installation to complete.
SSH into your Server as root and run the following commands:
# login server by SSH
ssh root@dokku.me
# Updating apt-get
sudo apt-get update # Fetches the list of available updates
sudo apt-get upgrade # Strictly upgrades the current packages
sudo apt-get dist-upgrade # Installs updates (new ones)
@hapiben
hapiben / provider.tf
Created May 19, 2017 01:59 — forked from robmorgan/provider.tf
Use Terraform to create a droplet on Digital Ocean
variable "do_token" {}
variable "pub_key" {}
variable "pvt_key" {}
variable "ssh_fingerprint" {}
provider "digitalocean" {
token = "${var.do_token}"
}
@hapiben
hapiben / database_cleaner.rb
Created November 17, 2016 07:56 — forked from jsteiner/database_cleaner.rb
Database Cleaner
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
@hapiben
hapiben / spca-wellington-flickr-parser.rb
Last active November 4, 2016 02:23
Example SJ Manager parser for SPCA Wellington Flickr
# Content Parner: Wellington SPCA
# Data Source: SPCA Wellington Flickr
class SPCAWellingtonFlickr < SupplejackCommon::Xml::Base
base_url 'https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=66881cbc6259eae63ceb6d6453159892&user_id=73889498@N04&photoset_id=72157628780736141&privacy_filter=1&extras=description,%20license,%20date_taken,%20owner_name,%20geo,%20tags,%20media,%20machine_tags,%20url_m,%20url_z,%20url_o&format=rest'
paginate page_parameter: 'page', type: 'page', per_page_parameter: 'per_page', per_page: 100, page: 1, total_selector: '//*[1]/@total'
record_selector '//photo'
record_format :xml
throttle host: 'api.flickr.com', delay: 1

Types

A type is a collection of possible values. An integer can have values 0, 1, 2, 3, etc.; a boolean can have values true and false. We can imagine any type we like: for example, a HighFive type that allows the values "hi" or 5, but nothing else. It's not a string and it's not an integer; it's its own, separate type.

Statically typed languages constrain variables' types: the programming language might know, for example, that x is an Integer. In that case, the programmer isn't allowed to say x = true; that would be an invalid program. The compiler will refuse to compile it, so we can't even run it.

Multiple MySQL Versions with Homebrew

For homebrew version 0.9.5.

brew -v # => Homebrew 0.9.5

Install the current version of mysql.

# Install current mysql version

brew install mysql

Atbash is a simple substitution cipher possible with any known alphabet. It emerged around 500-600 BCE. It works by substituting the letters of an alphabet with another.

English alphabets in order is the constant.

CONSTANT = 'abcdefghijklmnopqrstuvwxyz'

A random shuffle of the constant is the ciper.

Example cipher: zyxwvutsrqponmlkjihgfedcba

@hapiben
hapiben / app.js
Created May 8, 2016 21:02 — forked from benlesh/app.js
Angular - Basics of Unit Testing a Controller
var app = angular.module('myApp', []);
/* Set up a simple controller with a few
* examples of common actions a controller function
* might set up on a $scope. */
app.controller('MainCtrl', function($scope, someService) {
//set some properties
$scope.foo = 'foo';
$scope.bar = 'bar';
@hapiben
hapiben / Install Ruby and RubyGems
Created February 24, 2016 01:37 — forked from chiraggude/Install Ruby and RubyGems
Install Ruby 2.1.1 and RubyGems 1.8.25 on CentOS 6.5
# Install Ruby
wget http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz
tar xvzf ruby-2.1.1.tar.gz
cd ruby-2.1.1
./configure --prefix=/usr
make
make install
# remove "ruby-2.1.1" folder in /root
// kills long running ops in MongoDB (taking seconds as an arg to define "long")
// attempts to be a bit safer than killing all by excluding replication related operations
// and only targeting queries as opposed to commands etc.
killLongRunningOps = function(maxSecsRunning) {
currOp = db.currentOp();
for (oper in currOp.inprog) {
op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
print("Killing opId: " + op.opid