This file contains 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
module MyConcern | |
def shared_method | |
#do something with method_specific_to_class | |
end | |
def method_specific_to_class | |
raise NotImplementedError.new | |
end | |
end | |
class MyClass |
This file contains 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
SqlCondition.new(operator, left_side, right_side).to_query(scope) | |
input = "(attendees.id = 1 OR id < 2)" | |
sql_condition1 = SqlCondition.new('=' , "attendees.id", 1).to_query(Ticket) | |
#leverage SqlAttribute in this class | |
sql_condition1.to_query #=> "select * from tickets WHERE tickets.id < 1" | |
sql_condition2 = SqlCondition.new('=' , "attendees.id", 1).to_query(Ticket) |
This file contains 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
var ScoreUpdater = function(scores){ | |
this.scores = scores | |
} | |
ScoreUpdater.prototype.avgScore = function(){ | |
var sum = 0; | |
for (var i = 0; i < this.scores.length; i++) { | |
sum += parseInt(this.scores[i], 10); | |
} | |
var avg = sum / this.scores.length; | |
} |
This file contains 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
--#This code blows up | |
myFunction :: Ord a => [a] -> [a] | |
myFunction inputArray = reversedArray where | |
reversedArray :: Ord a => [a] | |
reversedArray = reverse inputArray | |
main :: IO () | |
main = print $ myFunction [1,2,3] | |
--#Below code works |
This file contains 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 Database.Persist.Sql | |
import qualified Database.Persist.TH as DPTH | |
--Consider the followering database structure | |
DPTH.share [DPTH.mkPersist DPTH.sqlSettings, DPTH.mkMigrate "migrateAll"] [DPTH.persistLowerCase| | |
User | |
name T.Text | |
UserPost | |
user_id UserId | |
post_id PostId |
This file contains 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
//Normal Approach: | |
const NameComponent = React.createClass({ | |
propType: { name: React.propTypes.String }, | |
render: function(){ | |
return <h1> {{ this.props.name }} </h1> | |
} | |
}) | |
React.createClass({ |
OlderNewer