Skip to content

Instantly share code, notes, and snippets.

View pmbanugo's full-sized avatar
:shipit:

Peter Mbanugo pmbanugo

:shipit:
View GitHub Profile
@pmbanugo
pmbanugo / BaseRepository.cs
Last active September 26, 2023 06:46
Implementation of the Repository and UnitOfWork pattern using Entity Framework.
// License: Apache 2.0
// A generic base repository which other repositories (if needed) can inherit from
public class BaseRepository<TEntity> : IEntityRepository<TEntity> where TEntity : class
{
internal DataContext context;
internal DbSet<TEntity> dbSet;
public BaseRepository(DataContext context)
{
@pmbanugo
pmbanugo / ChatHub.cs
Created August 11, 2016 10:41
Using SimpleInjector with SignalR: Injecting Services into SignalR Hubs.
public class ChatHub : Hub
{
private readonly Container _container;
public ChatHub(Container container)
{
_container = container;
}
public override Task OnConnected()
@pmbanugo
pmbanugo / vue-for-jQuery developers
Created July 11, 2018 12:18
Vue for jQuery developers
Vue.js is a framework for building web applications. It has a reactivity system that allows you to model and manage your application state such that when data changes, it's reflected in the UI, without you having to query the DOM. It's reactivity system makes state management simple and easy. With all the buzz around JS frameworks, you may have read about Vue and want to get into using Vue as a developer familiar withjQuery. Perhaps, you just keep seeing things about Vue appear in your favorite newsletters and you're wondering how you can make the transition to Vue. In this post, I'll show you fundamental components of Vue that you need to know to get started with as a jQuery developer.
# Adding Vue.js to your app
The first thing you do is to add a reference to Vue.js to (In or to?) your project. There are various ways you can do this but I'll focus on using a script reference on the page. So add `<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>` to your page. Once added, you then
@pmbanugo
pmbanugo / shipment-reducer.js
Created February 6, 2019 16:23
describes how findShipment could work for SL vertical
```
export const findShipments = (location, locationIsGeoLocation) => async (dispatch) => {
dispatch(asyncRequest({reducerName}))
const store = getStore()
const promises = [
store.shipment.find({location, locationIsGeoLocation})
]
// If the location is a geo location we need to filter the shipments to only
// include those that are valid locations for the users geo location. This way
// we exclude shipments for locations that the user does not have the funder.
class App extends React.Component {
render() {
return (
<div className="App">
<h1>Conversational UI</h1>
<Chat placeholder={"Type here..."} width={400}></Chat>
</div>
);
}
}
constructor(props) {
super(props);
this.user = undefined;
this.bot = { id: "0", name: "bot" };
this.state = {
messages: [
{
author: this.bot,
timestamp: new Date(),
<Chat
user={this.user}
messages={this.state.messages}
onMessageSend={this.addMessage}
placeholder={"Type here..."}
width={400}
></Chat>
addMessage = ({ message }) => {
if (!this.user) {
this.user = { name: message.text, id: Date.now().toString() };
let newMessage = Object.assign({}, message);
newMessage.text = `Welcome to the chat ${message.text}!`;
newMessage.author = this.bot;
this.setState({
messages: [...this.state.messages, newMessage]
initialiseChatClient = async () => {
const response = await fetch("http://localhost:8080/v1/token", {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
id: this.user.id,
name: this.user.name
onNewMessage = event => {
let message = {
text: event.message.text,
author: event.message.user,
timestamp: event.message.created_at
};
this.setState({
messages: [...this.state.messages, message]
});