Skip to content

Instantly share code, notes, and snippets.

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
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)
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;
}
@jvans1
jvans1 / ScopedTypeVariablesTest.hs
Created May 23, 2015 17:20
ScopedTypeVariables
--#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
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
@jvans1
jvans1 / reactex.js
Created November 30, 2016 17:23
Returning JSX
//Normal Approach:
const NameComponent = React.createClass({
propType: { name: React.propTypes.String },
render: function(){
return <h1> {{ this.props.name }} </h1>
}
})
React.createClass({