This file contains 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
#!/usr/bin/env python3 | |
"""Chaincode Exercise | |
Try getting node 1 to mine another block, | |
send it to node 2, and check that node 2 received it. | |
""" | |
from collections import defaultdict | |
from test_framework.blocktools import ( | |
create_block, |
This file contains 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
package main | |
import ( | |
"errors" | |
"fmt" | |
"math/rand" | |
"strconv" | |
"sync" | |
"time" | |
) |
This file contains 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
func AwaitAll[Input any, Response any](sliceOfInputs []Input, asyncFunc func(Input) Response) []Response { | |
responses := make([]Response, len(sliceOfInputs)) | |
var waitGroup sync.WaitGroup | |
for i, input := range sliceOfInputs { | |
waitGroup.Add(1) | |
go func(i int, input Input) { | |
responses[i] = asyncFunc(input) | |
waitGroup.Done() |
This file contains 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
package main | |
import ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
func main() { | |
// Start request limiter |
This file contains 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
package main | |
import ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
func main() { | |
// Create request limiter |
This file contains 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 { Injectable } from '@nestjs/common'; | |
import { mapLimit } from 'async'; | |
import * as firebase from 'firebase-admin'; | |
import { BatchResponse } from 'firebase-admin/lib/messaging/messaging-api'; | |
import { chunk } from 'lodash'; | |
import * as shell from 'shelljs'; | |
export interface ISendFirebaseMessages { | |
token: string; | |
title?: string; |
This file contains 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 { Injectable } from '@nestjs/common'; | |
import { mapLimit } from 'async'; | |
import * as firebase from 'firebase-admin'; | |
import { BatchResponse } from 'firebase-admin/lib/messaging/messaging-api'; | |
import { chunk } from 'lodash'; | |
import * as shell from 'shelljs'; | |
export interface ISendFirebaseMessages { | |
token: string; | |
title?: string; |
This file contains 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 { Injectable } from '@nestjs/common'; | |
import * as firebase from 'firebase-admin'; | |
import { BatchResponse } from 'firebase-admin/lib/messaging/messaging-api'; | |
import * as shell from 'shelljs'; | |
@Injectable() | |
export class NotificationsService { | |
... | |
public async sendAll(messages: firebase.messaging.TokenMessage[], dryRun?: boolean): Promise<BatchResponse> { |
This file contains 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 { Injectable } from '@nestjs/common'; | |
import * as firebase from 'firebase-admin'; | |
@Injectable() | |
export class NotificationsService { | |
constructor() { | |
// For simplicity these credentials are just stored in the environment | |
// However these should be stored in a key management system | |
const firebaseCredentials = JSON.parse(process.env.FIREBASE_CREDENTIAL_JSON); | |
firebase.initializeApp({ |
This file contains 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
const AWS = require('aws-sdk'); | |
const sns = new AWS.SNS({ apiVersion: '2010-03-31' }); | |
exports.handler = async (event, context) => { | |
let body; | |
let statusCode = '200'; | |
const { origin } = event.headers; | |
const acceptedOrigins = ['http://localhost:8080', 'https://mywebsite.com']; // PLACE PROPER WEBSITE ORIGIN | |
const headers = { | |
'Access-Control-Allow-Headers': 'Content-Type', |
NewerOlder