anchor
stringlengths
10
14.3k
positive
stringlengths
10
14.9k
rand generates pseudo random from 01 rand(10) generates pseudo random from 010 we use it to get something like 4.41445946155691
def random_float rand * rand(10) end
Takes a hash as its argument. The key is a symbol or an array of symbols. These symbols correspond to method names, instance variable names, or constant names (see def_delegator). The value is the accessor to which the methods will be delegated. :callseq: delegate method => accessor delegate [method, method, ...] => ac...
def instance_delegate(hash) hash.each do |methods, accessor| unless defined?(methods.each) def_instance_delegator(accessor, methods) else methods.each {|method| def_instance_delegator(accessor, method)} end end end
Perform replacement on specific (un)hyphenated config directives.
def unhyphenate(string) string.to_s.gsub(/(pre|post)xfer/, '\1-xfer') end
The client code works with complex subsystems through a simple interface provided by the Facade. When a facade manages the lifecycle of the subsystem, the client might not even know about the existence of the subsystem. This approach lets you keep the complexity under control.
def client_code(facade) puts facade.operation end
Retrieve all the attribute names (keys) from the session. like Hashkeys
def keys getAttributeNames.to_a end
Raise an error if the payment failed or if the signature is invalid
def validate! Cybersource::Security.validate_signature!(@fields['signature'], signed_data) raise PaymentFailed unless payment_success? self end
Never trust parameters from the scary internet, only allow the white list through.
def article_params params.require(:category).permit(:title, :description, :weight) end
remove files / dirs from collection, which are located below a collected dir
def remove_collection_redundancy redundant_file_count = 0 redundant_dir_count = 0 redundant_files = [] redundant_dirs = [] session[@pallet.collection][:directories].each do |dir| session[@pallet.collection][:files].each do |file| if file.starts_with?(dir + '/') logger.debug ...
Unfollow a user by id
def unfollow(other_user_id) user_to_unfollow = User.find_by(id: other_user_id) active_relationships.find_by(followed_id: user_to_unfollow.id).destroy end
imperials is the imperials value
def metrics standard.unit.convert_to_metric imperials end
Get Estimated Wait Time
def get_routing_queue_estimatedwaittime(queue_id, opts = {}) data, _status_code, _headers = get_routing_queue_estimatedwaittime_with_http_info(queue_id, opts) return data end
function for creating new features to the EnsEMBL Sequence object
def create_features_ensembl_seq_obj(bioseq,targets) targets.each do |key,value| f1 = Bio::Feature.new("target_CTTCTT","#{key[0]}..#{key[1]}") #im no sure if it is a interior coding exon f1.append(Bio::Feature::Qualifier.new('interior coding exon', "#{value[0]}")) f1.append(Bio:...
Returns the unique classes and modules discovered by RDoc. ::complete must have been called prior to using this method.
def unique_classes_and_modules @unique_classes + @unique_modules end
Some posts have an unwatermarked version of the image. Usually it's lower resolution and lower JPEG quality than the watermarked image. Multiimage posts will have only one unwatermarked URL.
def unwatermarked_url return nil if api_response["article_image_url"].nil? Source::URL.parse(api_response["article_image_url"]) end
GET /prospectives/new GET /prospectives/new.json
def new @prospective = Prospective.new respond_to do |format| format.html # new.html.erb format.json { render :json => @prospective } end end
The node is a unique state within the system e.g. x,y coordinate
def node [@x, @y] end
wookay.noh at gmail.com L lowercase letters. D words in this language. A pattern consists of exactly L tokens Each token is either a single lowercase letter (the scientists are very sure that this is the letter) or a group of unique lowercase letters surrounded by parenthesis ( and ). The first line of input contains 3...
def make_pattern pattern state = :close rule = '' last_ch = '' pattern.split('').each do |ch| case ch when '(' state = :open rule << '(' when ')' state = :close rule << ')' else case state when :open case last_ch when '(' else ...
This method finds all the files with the mentioned groups and services
def grep_files_by_properties # I - filter on @properties[:grouping] keywords. property_filter = "@properties[:grouping]" # @services_to_run ||= [] @groups_to_run ||= [] # groups to run may contain something like ["g1,g2,g3","g4,g5,g6"] groups_to_run_filter = @groups_to_run.map {|g| ...
GET /thing_lists/1 GET /thing_lists/1.xml
def show @thing_list = ThingList.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @thing_list } end end
Joins the raw paragraph text and converts inline HardBreaks to the +hard_break+ text followed by the indent.
def text hard_break = nil @parts.map do |part| if RDoc::Markup::HardBreak === part then '%1$s%3$*2$s' % [hard_break, @indent, ' '] if hard_break else part end end.join end
Show the studios that have not produced films with director "Walter Hill".
SELECT Studio FROM film EXCEPT SELECT Studio FROM film WHERE Director = "Walter Hill"
Show the student id of the oldest student.
SELECT StuID FROM Student WHERE age = (SELECT max(age) FROM Student)
What is the total revenue of companies with revenue greater than the lowest revenue of any manufacturer in Austin?
SELECT sum(revenue) FROM manufacturers WHERE revenue > (SELECT min(revenue) FROM manufacturers WHERE headquarter = 'Austin')
In which country does Roberto Almeida?
SELECT country FROM customers WHERE first_name = "Roberto" AND last_name = "Almeida";
how many degrees were conferred between 1998 and 2002?
SELECT T1.campus , sum(T2.degrees) FROM campuses AS T1 JOIN degrees AS T2 ON T1.id = T2.campus WHERE T2.year >= 1998 AND T2.year <= 2002 GROUP BY T1.campus
Sort the names of all counties in ascending order of population.
SELECT County_name FROM county ORDER BY Population ASC
How many projects are there?
SELECT count(*) FROM Projects
List the locations of schools that do not have any player.
SELECT LOCATION FROM school WHERE School_ID NOT IN (SELECT School_ID FROM Player)
What are the different names and ages of every friend of either Dan or alice?
SELECT DISTINCT T1.name , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Dan' OR T2.friend = 'Alice'
What is the name of the activity that has the most faculty members involved in?
SELECT T1.activity_name FROM Activity AS T1 JOIN Faculty_participates_in AS T2 ON T1.actID = T2.actID GROUP BY T1.actID ORDER BY count(*) DESC LIMIT 1
Find the number of different airports which are the destinations of the American Airlines.
SELECT count(DISTINCT dst_apid) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid WHERE T1.name = 'American Airlines'
What are all the distinct participant ids who attended any events?
SELECT count(DISTINCT participant_id) FROM participants_in_Events
Compute the number of products with a price larger than or equal to $180.
SELECT count(*) FROM products WHERE price >= 180
Show details of all visitors.
SELECT Tourist_Details FROM VISITORS
Find the first and last name of the author(s) who wrote the paper "Nameless, Painless".
SELECT t1.fname , t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t3.title = "Nameless , Painless"
Show the delegates and the names of county they belong to.
SELECT T2.Delegate , T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District
Which papers have the substring "Database" in their titles? Show the titles of the papers.
SELECT title FROM papers WHERE title LIKE "%Database%"
what are the details of the cmi masters that have the cross reference code 'Tax'?
SELECT T1.cmi_details FROM Customer_Master_Index AS T1 JOIN CMI_Cross_References AS T2 ON T1.master_customer_id = T2.master_customer_id WHERE T2.source_system_code = 'Tax'
What document type codes do we have?
SELECT document_type_code FROM Ref_Document_Types;
find the event names that have more than 2 records.
SELECT event_name FROM party_events GROUP BY event_name HAVING count(*) > 2
Which county do the delegates on "Appropriations" committee belong to? Give me the county names.
SELECT T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T2.Committee = "Appropriations"
Return the address of store 1.
SELECT T2.address FROM store AS T1 JOIN address AS T2 ON T1.address_id = T2.address_id WHERE store_id = 1
Show all countries and the number of people from each country.
SELECT country , count(*) FROM people GROUP BY country
What are the details of the project with no outcomes?
SELECT project_details FROM Projects WHERE project_id NOT IN ( SELECT project_id FROM Project_outcomes )
List all employees in the circulation history of the document with id 1. List the employee's name.
SELECT Employees.employee_name FROM Employees JOIN Circulation_History ON Circulation_History.employee_id = Employees.employee_id WHERE Circulation_History.document_id = 1;
What are all the location codes and location names?
SELECT location_code , location_name FROM Ref_locations
Find the grade taught in classroom 103.
SELECT DISTINCT grade FROM list WHERE classroom = 103
In 2014, what are the id and rank of the team that has the largest average number of attendance?
SELECT T2.team_id , T2.rank FROM home_game AS T1 JOIN team AS T2 ON T1.team_id = T2.team_id WHERE T1.year = 2014 GROUP BY T1.team_id ORDER BY avg(T1.attendance) DESC LIMIT 1;
What are the total purchases for members rated at level 6?
SELECT count(*) FROM purchase AS T1 JOIN member AS T2 ON T1.member_id = T2.member_id WHERE T2.level = 6
display the department id and the total salary for those departments which contains at least two employees.
SELECT department_id , SUM(salary) FROM employees GROUP BY department_id HAVING count(*) >= 2
Which country does customer with first name as Carole and last name as Bernhard lived in?
SELECT T2.country FROM Customers AS T1 JOIN Addresses AS T2 ON T1.customer_address_id = T2.address_id WHERE T1.first_name = "Carole" AND T1.last_name = "Bernhard"
Count the number of products with the 'hot' charactersitic.
SELECT count(*) FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id WHERE t3.characteristic_name = "hot"
Count the number of cinemas.
SELECT count(*) FROM cinema
Who is the director of movie Avatar?
SELECT director FROM Movie WHERE title = 'Avatar'
How many cities have a stadium that was opened before the year of 2006?
SELECT count(DISTINCT city) FROM stadium WHERE opening_year < 2006
What are the names of students who have more than one advisor?
SELECT T1.name FROM student AS T1 JOIN advisor AS T2 ON T1.id = T2.s_id GROUP BY T2.s_id HAVING count(*) > 1
What is the average number of customers across banks in the state of Utah?
SELECT avg(no_of_customers) FROM bank WHERE state = 'Utah'
Find the name of the person who has friends with age above 40 and under age 30?
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age > 40) INTERSECT SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age < 30)
Show all headquarters without a company in banking industry.
SELECT headquarters FROM company EXCEPT SELECT headquarters FROM company WHERE main_industry = 'Banking'
Find the dates on which more than one revisions were made.
SELECT date_of_latest_revision FROM Catalogs GROUP BY date_of_latest_revision HAVING count(*) > 1
Find the city and state of the bank branch named morningside.
SELECT city , state FROM bank WHERE bname = 'morningside'
What is the total share (in percent) of all the channels owned by CCTV?
SELECT sum(Share_in_percent) FROM channel WHERE OWNER = 'CCTV'
What are the names of products with price at most 200?
SELECT name FROM products WHERE price <= 200
What are the ids of the students who registered for course 301 most recently?
SELECT student_id FROM student_course_attendance WHERE course_id = 301 ORDER BY date_of_attendance DESC LIMIT 1
Find the total hours of the projects that scientists named Michael Rogers or Carol Smith are assigned to.
SELECT sum(T2.hours) FROM assignedto AS T1 JOIN projects AS T2 ON T1.project = T2.code JOIN scientists AS T3 ON T1.scientist = T3.SSN WHERE T3.name = 'Michael Rogers' OR T3.name = 'Carol Smith'
What is the name of the event that happened in the most recent year?
SELECT name FROM event ORDER BY YEAR DESC LIMIT 1
What are the names of the amenities that Smith Hall has?
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T1.dorm_name = 'Smith Hall'
Tell me the booking status code for the apartment with number "Suite 634".
SELECT T1.booking_status_code FROM Apartment_Bookings AS T1 JOIN Apartments AS T2 ON T1.apt_id = T2.apt_id WHERE T2.apt_number = "Suite 634"
What is the total number of gas stations that opened between 2000 and 2005?
SELECT count(*) FROM gas_station WHERE open_year BETWEEN 2000 AND 2005
What is the id and trade name of the medicines can interact with at least 3 enzymes?
SELECT T1.id , T1.trade_name FROM medicine AS T1 JOIN medicine_enzyme_interaction AS T2 ON T2.medicine_id = T1.id GROUP BY T1.id HAVING COUNT(*) >= 3
What are the unique labels for the albums?
SELECT count(DISTINCT label) FROM albums
Show ids for all the male faculty.
SELECT FacID FROM Faculty WHERE Sex = 'M'
How many games in total did team Boston Red Stockings attend from 2000 to 2010?
SELECT sum(T1.attendance) FROM home_game AS T1 JOIN team AS T2 ON T1.team_id = T2.team_id_br WHERE T2.name = 'Boston Red Stockings' AND T1.year BETWEEN 2000 AND 2010;
How many services are there?
SELECT count(*) FROM services
What is the weight of the shortest person?
SELECT Weight FROM people ORDER BY Height ASC LIMIT 1
Find the names of the users whose number of followers is greater than that of the user named "Tyler Swift".
SELECT T1.name FROM user_profiles AS T1 JOIN follows AS T2 ON T1.uid = T2.f1 GROUP BY T2.f1 HAVING count(*) > (SELECT count(*) FROM user_profiles AS T1 JOIN follows AS T2 ON T1.uid = T2.f1 WHERE T1.name = 'Tyler Swift')
List all the contact channel codes that were used less than 5 times.
SELECT channel_code FROM customer_contact_channels GROUP BY channel_code HAVING count(customer_id) < 5
Show the prices of the products named "Dining" or "Trading Policy".
SELECT Product_Price FROM Products WHERE Product_Name = "Dining" OR Product_Name = "Trading Policy"
Return the weight of the shortest person.
SELECT Weight FROM people ORDER BY Height ASC LIMIT 1
Show total hours per week and number of games played for students under 20.
SELECT sum(hoursperweek) , sum(gamesplayed) FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T2.age < 20
Count different addresses of each school.
SELECT count(DISTINCT dept_address) , school_code FROM department GROUP BY school_code
What are the names of artists who did not have an exhibition in 2004?
SELECT name FROM artist EXCEPT SELECT T2.name FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id WHERE T1.year = 2004
Find the names of swimmers who has a result of "win".
SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id WHERE RESULT = 'Win'
What is the name of the student who has the highest total credits in the History department.
SELECT name FROM student WHERE dept_name = 'History' ORDER BY tot_cred DESC LIMIT 1
What are the ids of suppliers which have an average amount purchased of above 50000 or below 30000?
SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id HAVING avg(total_amount_purchased) > 50000 OR avg(total_amount_purchased) < 30000
How many instruments does the song "Badlands" use?
SELECT count(DISTINCT instrument) FROM instruments AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE title = "Badlands"
Which tourist attractions does the visitor with detail 'Vincent' visit?
SELECT T1.Name FROM Tourist_Attractions AS T1 JOIN VISITS AS T2 ON T1.Tourist_Attraction_ID = T2.Tourist_Attraction_ID JOIN VISITORS AS T3 ON T2.Tourist_ID = T3.Tourist_ID WHERE T3.Tourist_Details = "Vincent"
What are the names of wines with scores higher than 90?
SELECT Name FROM WINE WHERE score > 90
What are the names and locations of all enzymes listed?
SELECT name , LOCATION FROM enzyme
What is the maximum enrollment across all schools?
SELECT max(Enrollment) FROM university
Show all dates of transactions whose type code is "SALE".
SELECT date_of_transaction FROM TRANSACTIONS WHERE transaction_type_code = "SALE"
What is the name of the document with the most number of sections?
SELECT t1.document_name FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code = t2.document_code GROUP BY t1.document_code ORDER BY count(*) DESC LIMIT 1
How many faculty members do we have for each faculty rank?
SELECT rank , count(*) FROM Faculty GROUP BY rank
What is the course title of the prerequisite of course Mobile Computing?
SELECT title FROM course WHERE course_id IN (SELECT T1.prereq_id FROM prereq AS T1 JOIN course AS T2 ON T1.course_id = T2.course_id WHERE T2.title = 'Mobile Computing')
Return the minimum, average and maximum distances traveled across all aircrafts.
SELECT min(distance) , avg(distance) , max(distance) FROM Aircraft
What information do you have on colleges sorted by increasing enrollment numbers?
SELECT * FROM College ORDER BY enr
Give me a list of cities whose temperature in Mar is lower than that in July and which have also served as host cities?
SELECT T1.city FROM city AS T1 JOIN temperature AS T2 ON T1.city_id = T2.city_id WHERE T2.Mar < T2.Jul INTERSECT SELECT T3.city FROM city AS T3 JOIN hosting_city AS T4 ON T3.city_id = T4.host_city
For each zip code, find the ids of all trips that have a higher average mean temperature above 60?
SELECT T1.id FROM trip AS T1 JOIN weather AS T2 ON T1.zip_code = T2.zip_code GROUP BY T2.zip_code HAVING avg(T2.mean_temperature_f) > 60
What are the codes of card types that have 5 or more cards?
SELECT card_type_code FROM Customers_cards GROUP BY card_type_code HAVING count(*) >= 5
What are the names of all clubs?
SELECT clubname FROM club