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
//Normal Approach: | |
const NameComponent = React.createClass({ | |
propType: { name: React.propTypes.String }, | |
render: function(){ | |
return <h1> {{ this.props.name }} </h1> | |
} | |
}) | |
React.createClass({ |
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 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 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
--#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 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
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 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
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 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
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 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
angular.module('myApp', []).factory( 'AuthService', ["$cookieStore", '$http', | |
var currentUser; | |
return { | |
login: function(email, password, fn) { | |
currentUser = //Login work with $http | |
$cookieStore.put("currentUser", currentUser.name) | |
}, | |
logout: function(){ | |
//Logout work with $http |
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
angular.module('myapp').config([ '$httpProvider', function ($httpProvider) { | |
$httpProvider.interceptors.push('globalErrorInterceptor'); | |
}]); | |
angular.module('myapp').factory('globalErrorInterceptor', ['$q', '$rootScope', '$cookieStore', '$injector', '$location', 'PathService', 'AlertService', | |
function ($q, $rootScope, $cookieStore, $injector, $location, Path, Alert) { | |
$rootScope.showSpinner = false; | |
$rootScope.http = null; | |
return { | |
'response': function (response) { | |
return response || $q.when(response) |
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
def mode(array) | |
#Hash.new is good here because the 0 is default for blank values | |
hash = Hash.new(0) | |
#Just use an array literal | |
max = [] | |
array.each {|x| hash[x] += 1 } | |
hash.select do |key, value| |
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 Ticket < ActiveRecord::Base | |
class TicketConfirmer | |
attr_reader :ticket, :confirmation_errors | |
delegate :user, :grouper :to => :ticket | |
def initialize(ticket) | |
@ticket = ticket | |
@confirmation_errors = [] | |
end | |
def can_confirm? |
NewerOlder