Skip to content

Instantly share code, notes, and snippets.

View caviles's full-sized avatar

Cesar caviles

View GitHub Profile
@caviles
caviles / login.js
Created January 19, 2018 21:23
Firebase Auth C# Clientside JS Login
var config = {
apiKey: "***",
authDomain: "***",
databaseURL: "***",
projectId: "***",
storageBucket: "***",
messagingSenderId: "***"
};
firebase.initializeApp(config);
smart pointers
shared pointer - bumps ref
weak pointer - doesn't bump ref
uniqiue pointer - can't be copied
auto pointer - this is a weak attempt at smart pointers - don't use this it has many problems in containers
pResource=std::make_shared<Resource>("Resource for " + GetName()); // init a shard ptr
C++ templates are set at compile time not runtime like C#, java
//returns max of two values
template <class T>
T max(T& t1, T& t2){
return t1 < t2 ? t2 : t1;
}
overload operators in c++ often
instead creating a Add() overload + and or +=
Change the hover over object value in the debug window https://msdn.microsoft.com/en-us/library/x810d419.aspx
null coelescing opertor
string i = name ?? "no name"; these is a shorted version of the ternary ? name : "no name"
//deep checks and =
string i = name ?? lname ?? fname ?? "no name"; these is a shorted version of the ternary ? name : "no name"
avoid .Result Or Wait on task as it will block threads and can lead to deadlocks
always wrap your calls in try catch as the async errors are generally swallowed by the framework
public async Task<Customer> Get(int id)
{
// you are on a particular thread here
var customer = await SomeAsyncFunctionThatGetsCustomer(id).ConfigureAwait(false); // doesn't have find the orginal thread it used so is much faster
// now you are on a different thread! will that cause problems?
return customer;
}
// Student collection
IList<Student> studentList = new List<Student>>() {
new Student() { StudentID = 1, StudentName = "John", Age = 13} ,
new Student() { StudentID = 2, StudentName = "Moin", Age = 21 } ,
new Student() { StudentID = 3, StudentName = "Bill", Age = 18 } ,
new Student() { StudentID = 4, StudentName = "Ram" , Age = 20} ,
new Student() { StudentID = 5, StudentName = "Ron" , Age = 15 }
};
// LINQ Query Syntax to find out teenager students
a delegate is a function pointer
when we work with events we use a delegate which inherie from multicast deletegate
a delegate is the pipeline between the event and the event handler
button.Click += EventHandler(btnHit_Click) // here when the click event is raised the eventhandler delegate will call the btnHit_CLick method
public delegate void WorkHandler(string job, int time) // this delegate can be used as the pipeline for methods that take these two args
public void work(string job, int time)
const Card = (props) => {
return (
<div style={{margin:'1em'}}>
<img width="175" src={props.avatar_url} />
<div style={{display:"inline-block", marginLeft:"10px"}}>
{props.name}
<div>{props.company}</div>
</div>
</div>
const Card = (props) => {
return (
<div style={{margin:'1em'}}>
<img width="175" src={props.avatar_url} />
<div style={{display:"inline-block", marginLeft:"10px"}}>
{props.name}
<div>{props.company}</div>
</div>
</div>
class Button extends React.Component {
handleClick = () => {
this.props.onClickFn(this.props.incrementValue);
};
render () {
return(
<button onClick={this.handleClick}>
+{this.props.incrementValue}</button>