Skip to content

Instantly share code, notes, and snippets.

View chriswitko's full-sized avatar

Chris Witko chriswitko

View GitHub Profile
import React from "react";
import { StyleSheet, Text, View, Image } from "react-native";
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.detailsContainer}>
<Text style={styles.title}>Conference Keynote</Text>
<Text style={styles.subtitle}>Thursday, May 18</Text>
@svmotha
svmotha / tableLogCenter.py
Created June 11, 2017 06:45
Query and update DynamoDB tables using hash keys
from boto3.dynamodb.conditions import Key
class logCenter(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
# Update new followers to database (have already recieved direct messages)
def dynamoPut(self, follower, table):
table.put_item(
'use strict';
// Dependencies
const gcloud = require('google-cloud', {
projectId: 'sara-bigquery',
keyfileName: 'keyfile.json'
});
const vision = gcloud.vision();
const fs = require('fs');
const async = require('async');
@danieldunderfelt
danieldunderfelt / historyrouter.js
Created May 5, 2017 06:41
A router based on hashrouter that uses the history api where available.
/**
This router depends on the history package:
yarn add history
Simple router for switching between routes. Based on
[hashrouter.js](https://gist.github.com/danieldunderfelt/4d016333a947764c1a5687d26d48ca27)
Suitable for MobX/Redux architecture and especially
handy for tabs, which is the reason why it exists.
@qx133
qx133 / tryEthereum.js
Created April 30, 2017 14:18
Try out Ethereum using only nodejs and npm!
var Web3 = require('web3');
var util = require('ethereumjs-util');
var tx = require('ethereumjs-tx');
var lightwallet = require('eth-lightwallet');
var txutils = lightwallet.txutils;
var web3 = new Web3(
new Web3.providers.HttpProvider('https://rinkeby.infura.io/')
);
var address = '0x8D68583e625CAaE969fA9249502E105a21435EbF';
var key = '1ce642301e680f60227b9d8ffecad474f15155b6d8f8a2cb6bde8e85c8a4809a';
FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /app
WORKDIR /app
ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock
RUN bundle install
ADD . /app
EXPOSE 3000
CMD rails s -p 3000
@sxywu
sxywu / .block
Last active November 28, 2017 16:28
Film Flowers #axidraw
license: gpl-3.0

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@wojteklu
wojteklu / bayes.go
Created February 28, 2017 20:58
Multinomial naive Bayes classifier
package bayes
// Classifier implements the Naive Bayes Classifier.
type Classifier struct {
classPerWordCount map[string]int
classPerDocument map[string]int
wordClassCount map[string]map[string]int
documentsCount int
}
@mmirolim
mmirolim / naive_bayes.go
Created January 31, 2017 10:12
Naive Bayes example in golang for text classification
package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
"sync"