##Create a new app with a mysql driver mix phoenix.new phoenix_blog --database mysql
##Create the db
mysql -u root
CREATE DATABASE phoenix_blog_dev
| set_trace_func proc { |event, file, line, id, binding, classname| | |
| printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname | |
| } |
| def (t = Object.new).yolo(other) | |
| puts other | |
| end | |
| t.yolo(2) | |
| # 2.1.6 :023 > t.yolo(2) | |
| # 2 | |
| t = String.new("yolo") |
| redis = Redis.new(:url => 'redis://localhost:6379/1') | |
| disconnected_at = nil | |
| loop do | |
| begin | |
| if disconnected_at && (size = redis.keys('testing:*').count) | |
| puts "reconnected_at #{Time.now}" | |
| puts "KeysSize: #{size}" |
As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.
All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.
| { | |
| id: 52, | |
| description: "Yannis PK,(1st time in Athens) / Nick Mason / Evi Sidiropoulou / / Maria Papidaki (best Radio 92,6)!!!", | |
| name: "OdySPACE Presents : Yannis PK , Evi Sidiropoulou, Maria Papidaki, Nick Mason", | |
| start_time: "2016-10-22T23:30:00.000+03:00", | |
| end_time: "2016-10-23T07:00:00.000+03:00", | |
| page_id: 16, | |
| place_id: 10, | |
| fb_id: "1149022598488237", | |
| created_at: "2016-10-13T22:12:54.000+03:00", |
| require 'mkmf' | |
| require 'fileutils' | |
| unless have_library 'snappy_ext' | |
| dst = File.dirname File.expand_path __FILE__ | |
| tar = 'tar' | |
| tar = 'gnutar' if find_executable 'gnutar' | |
| ver = "1.1.1" |
| # Run it | |
| # curl -O https://gist.githubusercontent.com/msroot/420e3aba4fb4c4f96a63c59cc5b954e7/raw/41961b927e6d261e4264df2d3ce53406c515ff74/kss.rb && ruby kss.rb | |
| `osascript -e 'tell application "iTunes" to play playlist named "My Top Rated" '` | |
| %w(❤️ 🍍 🌴 🎹 🍸 🎼 ☀️ ).permutation.to_a.map{|a| | |
| p a.join(" ") | |
| sleep 1 | |
| } |
| # usage: $ ruby console.rb | |
| require 'irb' | |
| module IRB | |
| def self.start_session(binding) # call this method to drop into irb | |
| unless @__initialized | |
| args = ARGV | |
| ARGV.replace(ARGV.dup) |
| #!/usr/bin/env bash | |
| # This script prints out all of your Redis keys and their size in a human readable format | |
| # Copyright 2013 Brent O'Connor | |
| # License: http://www.apache.org/licenses/LICENSE-2.0 | |
| human_size() { | |
| awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } ' | |
| } |