Skip to content

Instantly share code, notes, and snippets.

View jacobzlogar's full-sized avatar
🌴
Working

Jacob Zlogar jacobzlogar

🌴
Working
View GitHub Profile
@jeskew
jeskew / SnsBroadcaster.php
Last active July 28, 2020 19:14
Laravel broadcasting with SNS
<?php
use Aws\Sns\SnsClient;
use Illuminate\Contracts\Broadcasting\Broadcaster;
class SnsBroadcaster implements Broadcaster
{
/** @var SnsClient */
private $sns;
/** @var array */
@jsanders
jsanders / prime_sieve.rs
Last active May 19, 2022 16:41
Rust Sieve of Eratosthenes
// Find all prime numbers less than n
fn small_primes(bound: uint) -> ~[uint] {
// num is considered prime as long as primes[num] is true
// Start with all evens besides 2 filtered out
let mut primes = std::vec::from_fn(bound+1, |num| num == 2 || num & 1 != 0);
// Start at 3 and step by 2 because we've already filtered multiples of 2
for num in count(3u, 2).filter(|&num| primes[num]).take_while(|&num| num * num <= bound) {
// Mark prime num's multiples non-prime
// We can start at num^2 because smaller non-primes have already been eliminated