Skip to content

Instantly share code, notes, and snippets.

class Rental...
double getCharge() {
double result = 0;
switch (getMovie().getPriceCode()) {
case Movie.REGULAR:
result += 2;
if (getDaysRented() > 2)
result += (getDaysRented() - 2) * 1.5;
break;
case Movie.NEW_RELEASE:
class Movie...
double getCharge(int daysRented) {
double result = 0;
switch (getPriceCode()) {
case Movie.REGULAR:
result += 2;
if (daysRented > 2)
result += (daysRented - 2) * 1.5;
break;
case Movie.NEW_RELEASE:
class Rental...
double getCharge() {
return _movie.getCharge(_daysRented);
}
class Rental...
int getFrequentRenterPoints() {
if ((getMovie().getPriceCode() == Movie.NEW_RELEASE) &&
getDaysRented() > 1)
return 2;
@rightson
rightson / config-RN2483.py
Created October 31, 2016 15:00
config script for RN2483
import serial
class Serial:
BAUDRATE = 57600
TIMEOUT = 1
SERIAL_PORT = '/dev/ttyUSB0'
def __init__(self):
self.ser = serial.Serial(
>>> import re
>>> src = 'LAYOUT PRIMARY "source_string"'
>>> dest = "dest_string"
>>> re.sub(r'(LAYOUT PRIMARY) "\w+"', '\\1 "%s"' % dest, src)
'LAYOUT PRIMARY "dest_string"'
@rightson
rightson / vagrantfile
Last active April 21, 2017 04:54
my Vagrantfile for centos-6.7 box
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.putty.modal = true
config.vm.box = "bento/centos-6.7"
config.vm.provision "shell", inline: <<-SHELL
yum update -y
yum install -y epel-release
yum install -y http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm
@rightson
rightson / .Xresources
Created May 2, 2017 23:27
molokai color theme for xterm (from vreon/.Xresources)
*xterm*font: 12x24
*xterm*background: #101010
*xterm*foreground: #d0d0d0
*xterm*cursorColor: #d0d0d0
*xterm*color0: #101010
*xterm*color1: #960050
*xterm*color2: #66aa11
*xterm*color3: #c47f2c
*xterm*color4: #30309b
*xterm*color5: #7e40a5
@rightson
rightson / git-clean-large-object.sh
Last active June 7, 2017 07:05
Script to clean up large object from git repository
# Reference: http://stevelorek.com/how-to-shrink-a-git-repository.html
function discoveryLargeGitObject() {
IFS=$'\n';
# list all objects including their size, sort by size, take top 10
objects=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head`
echo "All sizes are in kB. The pack column is the size of the object, compressed, inside the pack file."
# from https://stackoverflow.com/questions/1128496/to-get-a-prompt-which-indicates-git-branch-in-zsh
# get the name of the branch we are on
git_prompt_info() {
git branch | awk '/^\*/ { print $2 }'
}
get_git_dirty() {
git diff --quiet || echo '*'
}
autoload -U colors
@rightson
rightson / server.js
Created October 20, 2017 10:04
Koa example minimal server
'use strict';
const path = require('path');
const zlib = require('zlib');
const winston = require('winston');
const Koa = require('koa');
const Router = require('koa-router');
const koaLogger = require('winston-koa-logger');
const convert = require('koa-convert');
const compress = require('koa-compress');