Skip to content

Instantly share code, notes, and snippets.

View agushuley's full-sized avatar
💭
living life, loving wife and children, writing code

Andrij Hu agushuley

💭
living life, loving wife and children, writing code
View GitHub Profile
@agushuley
agushuley / bamboo-agents.sh
Last active December 9, 2015 10:12 — forked from yatesr/bamboo-agent
Init script for starting/stopping a bamboo agent
#!/bin/bash
# bamboo-agent Init script for running bamboo agent
#
# chkconfig: 2345 98 02
#
# description: Starts and stops bamboo agent
# This is just a delegator to the Bamboo agent script.
USER=apps
AGENTS_HOME=/opt/local/bamboo-agents
@agushuley
agushuley / gist:3817075
Created October 2, 2012 07:37
Scala for impatients, chapter 5, 4th task
class Time( private val _hour: Int, private val _minute: Int ) {
private val time = _hour * 60 + _minute;
def hour = _hour
def minute = _minute
def before( other: Time ) = other.time > time
override def toString(): String = hour + ":" + minute
}
@agushuley
agushuley / gist:3817034
Created October 2, 2012 07:24
Scala for impatients, chapter 5, 3th task
class Time( private var _hour: Int, private var _minute: Int ) {
if ( _minute > 59 ) {
_hour += ( _minute / 60 )
_minute = _minute % 60
}
if ( hour > 23 ) {
_hour = 23
}
@agushuley
agushuley / gist:3816922
Created October 2, 2012 06:53
Scala for impatients, chapter 5, 2th task
class Account {
private var balance: Double = 0;
def credit = if ( balance < 0 ) -balance else 0
def credit_=( value: Int ) {
balance = -value
}
def debit = if ( balance > 0 ) balance else 0
@agushuley
agushuley / gist:3816779
Created October 2, 2012 06:26
Scala for impatients, chapter 5, 1th task
class Counter {
private var counter: Int = 0;
def increment(): Int = {
if ( counter == Int.MaxValue ) {
counter = 0
} else {
counter += 1
}
counter
@agushuley
agushuley / gist:3808143
Created September 30, 2012 18:56
Scala for impatients, chapter 4, 2th task
var frequency = new scala.collection.mutable.HashMap[String, Int]
def process( word: String ): Unit = {
frequency += ( word -> ( frequency.getOrElse( word, 0 ) + 1 ) )
}
var in = new java.util.Scanner( new java.io.File ( "/Users/andriy/tmp/myfile.txt" ) )
while ( in.hasNext ) process ( in.next )
@agushuley
agushuley / gist:3806437
Created September 30, 2012 10:44
Scala for impatients, chapter 2, 10th assignment
def pow( x: Double, p: Int ): Double = {
if ( p == 1 ) x
else if ( p == 0 ) 1
else if ( p < 0 ) 1 / pow( x, -p )
else if ( p % 2 == 0 ) {
val y = pow( x, p / 2)
y * y
}
else pow( x, p - 1) * x
}
@agushuley
agushuley / clear-old-data.sh
Created February 9, 2012 08:40
Archive and remove old log files, rotate nginx files
#!/bin/sh
# Usage: ./clear-old-data `cat $HOME/var/run/nginx.pid` -USR1 $HOME/logs/*.log
if [ ! -z $1 ] ; then
_PID=$1
shift
_SIG=$1
shift
_YESTERDAY=`date -v -1d '+%Y-%m-%d'`