This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| host: localhost | |
| adapter: postgresql | |
| database: learn_db | |
| username: learn | |
| password: learn | |
| pool: 5 | |
| timeout: 5000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'active_record' | |
| dbconfig = YAML::load(File.open('database.yml')) | |
| ActiveRecord::Base.establish_connection(dbconfig) | |
| ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a')) | |
| class Employee < ActiveRecord::Base | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ----------- Set prompt to show working git branch ------------------ | |
| # inspired by fowlduck's http://gist.github.com/4477 | |
| # unfortuneately if I echo ansi codes it messes with line wrapping on the | |
| # command line, | |
| # guessing because unlike ansi codes in a VAR it doesn't know the real size of | |
| # the string when echo'd :( | |
| # doesn't matter if the codes are set using tput or straight up raw ansi | |
| function git_prompt { | |
| BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"` | |
| if [ -n "${BRANCH}" ]; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| str = "Can you modify me?" | |
| str.freeze | |
| str << " I'm trying." #this will raise TypeError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| str = "Can you modify me?" | |
| str.freeze | |
| if str.frozen? | |
| p "cannot modify string" | |
| else | |
| str = "string modified" | |
| p str | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FreezeTest | |
| def initialize(str) | |
| @text = str | |
| end | |
| end | |
| obj1 = FreezeTest.new("obj1") | |
| obj2 = FreezeTest.new("obj2") | |
| obj3 = obj1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| str = "Hello" | |
| str.freeze | |
| str_clone = str.clone | |
| puts "str_clone is still frozen" if str_clone.frozen? | |
| str_dup = str.dup | |
| puts "str_dup is not frozen" unless str_dup.frozen? | |
| # output: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.io.PrintWriter; | |
| import java.net.Socket; | |
| public class RequestProcessor { | |
| private Socket socket; | |
| public RequestProcessor(Socket socket) { | |
| this.socket = socket; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import static org.mockito.Mockito.verify; | |
| import static org.mockito.Mockito.when; | |
| import static org.mockito.Mockito.*; | |
| import java.io.ByteArrayInputStream; | |
| import java.io.ByteArrayOutputStream; | |
| import java.io.IOException; | |
| import java.net.Socket; | |
| import junit.framework.Assert; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static Calendar convertTimeToEST(long timeInMillSec) { | |
| Calendar cal = Calendar.getInstance(); | |
| TimeZone tz = cal.getTimeZone(); | |
| cal.setTimeInMillis(timeInMillSec); | |
| TimeZone estTz = TimeZone.getTimeZone("America/New_York"); | |
| Calendar estCal = Calendar.getInstance(estTz); | |
| estCal.setTimeInMillis(timeInMillSec); | |
| int tzOffset = tz.getOffset(cal.getTime().getTime()); | |
| int estTzOffset = estTz.getOffset(estCal.getTime().getTime()); |
OlderNewer