Monday, September 22, 2014

Inserting a Link To A Google Drive File in a Google Spreadsheet

It seems Google are changing how you use the Google Drive File Chooser which always looks a bit goofy if you are using it in a spreadsheet because of poor design.



I had a go to see if I can resize the dialog at all and I don't think so. Here's my version of their code which demonstrates how you can wire it to insert a link to a Google Drive file.

There's an example file here: Drive Dialog example. Simply go to the File > Make a copy menu to see the code using Tools > Script Editor menu.


Saturday, September 20, 2014

C++ Tutorial for Beginners 37 - C++ Exception Handling (Try Throw Catch)















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include<string>
#include <exception>
using namespace std;

int main()
{
try{
std::cout<<"Please enter age"<<std::endl;
int age=0;
std::cin>>age;
if(age>100 || age<0)
{
throw 'a';
}
}
catch(int e)
{
std::cout<<"Error No="<<e<<std::endl;
}
catch(char e)
{
std::cout<<"Error Char="<<e<<std::endl;
}
catch(...)
{
std::cout<<"Unknown Exception"<<std::endl;
}
}












--------------------------------------------------------------------

c++ throw exception example

rethrow exception c++ example

Try and Catch

c++ custom exception example

c++ exception inheritance example

Thursday, September 18, 2014

Where Do Good Ideas Come From?

Many people think ideas happen in a flash, a moment of inspiration, that eureka moment. They also believe that it's often "other people" that have ideas, either a boss or lone genius hunting down those illusive light bulbs.

The funny thing is, that the reality is, ideas can be slow things, taking time to come into being and most often they happen in discussion or collaboration. From what I've seen, the best ideas don't come from senior management, or from a sole genius but from people working together, people actually doing stuff in the real world. Many of these "good ideas" can be almost accidental.

My role at the university has been to both introduce people to the Google Apps suite, both evangelising them and working with people to help them realise their ideas.

Here's a story of an "accidental idea" that I think is good and is a great example of what I call "people actually stuff" and collaboration and discussion.

Someone in Facilities in Harry Fairhurst, let's call him Andrew, was talking to someone in the Communications Team, we can call her Jess because that's her name too. They came to me, Tom, and asked, "Can we have a spreadsheet to make the recording of seat availability in Harry Fairhurst easier?"

I didn't know that this information was collected. I showed them how to add drop downs and colours to a Google Spreadsheet. Job done.





I then discovered that someone actually regularly patrols the building and carries an android tablet. I had the thought that instead of it being a spreadsheet, which was OK but not ideal, it could be an app, better designed for updating on the move. It took me about half an hour to make an app that did that for them, updating the same spreadsheet, using Apps Script. Apps Script is a coding language based on JavaScript built into Google Spreadsheets, Sites and Docs and it's a fantastic tool for people who want to quickly make their ideas happen.


The story doesn't end here. Previously, I'd shared an office with Aimee, who'd discovered that with a little HTML hacking, we could show some Google data on the York website. And so the Jess added the seat availability page to our web site as a trial service. An accidental feature of the technology means that this chart is updated every 5 minutes, rather than twice a day like the web site.



And the story goes on. By now, only days after "launching" a trial service the Communications Team were already receiving positive feedback from students.

Next, Jess and Steve, seeing that the data could be displayed on the web site, asked if it could also be displayed on the big screens around Harry Fairhust. We found that the original spreadsheet looked a "bit lost" on the big screens, so wrote some code to "push" the data from the main spreadsheet to another sheet formatted with bigger fonts etc (shown below).

function copy_sheet(){
  //Simply makes a copy of the main sheet
  
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  
  var sheet = ss.getSheetByName("Seating availability")
  var range = sheet.getDataRange()
  var a1 = range.getA1Notation()
  var values = range.getValues()
  
  var destination_spreadsheet = SpreadsheetApp.openById('SHEET_ID')
  var destination_sheet = destination_spreadsheet.getSheetByName("Big Screen")
  var destination_range = destination_sheet.getRange(a1)
  destination_range.setValues( values )
  
  }



The trial Seating Availability service came into being after chance questions and discussions. It took little to no time to put together. It uses Google Spreadsheets, an app, an android tablet, a widget embedded in a web page and our big screens. It involved at least four or five people.

The is already hugely popular for all sorts of reasons. I heard from disability services that students with problems with anxiety love being able to avoid "nearly full" study spaces.

We will soon be adding extra areas and improving it based on feedback.

If you're still wondering where good ideas come from...






Saturday, September 13, 2014

C++ Tutorial for Beginners 35 - Introduction to Polymorphism in C++




















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include<string>
using namespace std;
class shape
{
public:
void setValues(int a ,int b){
width=a;
height=b;
}
protected:
int height ;
int width;
};
class rectangle : public shape
{
public:
int area(){
return (height * width);
}
};
class triangle : public shape
{
public:
int area(){
return (height * width/2);
}
};

int main()
{
rectangle rec;
triangle tri;
shape *poly1=&rec;
shape *poly2=&tri;
poly1->setValues(10,20);
poly2->setValues(10,20);

std::cout<<rec.area()<<std::endl;
std::cout<<tri.area()<<std::endl;
}












-------------------------------------------------------

Verwandte Suchanfragen zu polymorphism c++

c++ polymorphismus

polymorphismus c++ beispiel

c++ virtual

c++ virtual function

polymorph c++

c++ pure virtual

c++ tutorial virtual

c++ virtual function 0

Tuesday, September 2, 2014

Showing When An Appointment Slot is FULL using Google Forms and Apps Script

I'm sorry this isn't a finished solution you can just copy and paste. It's more of an example, sharing THAT this can easily be done which may help you figure out how to do it your case.



Lots of people at the University of York are using Google Forms to allow people to sign up to events. They use forms rather than Appointment Slots because they want to work with the data to generate registers for the people running the events.


But often these events have a capacity, that is, once 20 people have signed up to them, they're full.

There isn't much you can do with Google Forms to "live lookup" data and change form items if they're full, so we have developed workarounds to mimic this behaviour.

Firstly, having created our Form in the regular way, we create an extra sheet that keeps a track of how many people have have signed up, like this...


The count column has a formula in it like this...

=COUNTIF('Form responses 1'!G:G,B2)

...and the limit is a number we entered of how many places that slot has.

Secondly, we need to create a couple of functions that get fired when someone signs up to a session, like this...

function find_limits(rangeA1, their_choice){ //the values for the range and choice parsed in the main function
// the range is where you want to look in Group Totals var ss = SpreadsheetApp.getActiveSpreadsheet() var sheet = ss.getSheetByName("Group Totals") var range = sheet.getRange(rangeA1) var values = range.getValues() //get the count and limit values for the question's range for the user's choice for ( v in values){ var row = values[v] if (row[0] == their_choice){ return [row[1], row[2]] //the first value (row[0]) is their choice
// the second value (row[1]) is the count 
// the third value (row[2]) is the limit } } } function test_find_limits(){ Logger.log( find_limits("B3:E23", "11:45-12:00")) }

and

function check_availability(item_id, count, limit, their_choice){ var ss = SpreadsheetApp.getActiveSpreadsheet() var sheet = ss.getSheetByName("Group Totals") var form_id = "YOUR_FORM_ID_HERE" //the form ID is from the url. var form = FormApp.openById(form_id) var items = form.getItems() var item = form.getItemById(item_id).asListItem() var choices = item.getChoices() //pulls out the multiple choice question choices.  
//Can't pull out one particular choice so pulls them all out and iterates var choices_list = [ ] for (c in choices){ var choice = choices[c] if (choice.getValue() == their_choice){ if (count >= limit){ //It's up to the limit! choices_list.push(their_choice + " FULL!" ) 
}else{ choices_list.push(choices[c].getValue()) } }else{ choices_list.push(choices[c].getValue() ) } } item.setChoiceValues(choices_list) }


So, basically, when someone books an appointment, the script looks in the "Group Totals" sheet, and if the count is equal to the limited number of places, it changes the multiple choice items title to "10:00 - 10:30 FULL!".

What's interesting about this is that although you can't do live changes to the form, this script essentially changes the form items for the next person who uses it.

I did experiment with deleting the multiple choice item, but had a few funny results, so thought it best to just change its name. This can be a good idea anyway, to show to users that slots did exist but now they're gone.

Of course in this case someone can still book a full slot ( it doesn't prevent it) , but this process is, in our case, policed by a human anyway. This method is a way to heavily dissuade people from selecting full course slots.

Hope this helps.


 

© 2013 Klick Dev. All rights resevered.

Back To Top