Skip to content

Instantly share code, notes, and snippets.

View eladroz's full-sized avatar

Elad Rosenheim eladroz

View GitHub Profile
@eladroz
eladroz / [slug].json.js
Created April 4, 2022 08:24
Getting content from Contentful in a SvelteKit JSON resource
import { client } from '$lib/contentfulClient';
export async function get({ params }) {
const blog = await client.getEntries({
'fields.slug': params.slug,
content_type: 'blog-post'
});
if (blog?.items?.length > 0) {
return {
@eladroz
eladroz / [slug].svelte
Created April 4, 2022 08:18
Rendering a blog post from Contentful
<script context="module">
import { goto } from '$app/navigation';
export async function load({ fetch, params }) {
const url = `/${params.slug}.json`;
const res = await fetch(url);
if (res.ok) {
const { blog } = await res.json();
return {
props: {
@eladroz
eladroz / __layout.svelte
Created April 4, 2022 08:02
SvelteKit: invalidate page on content update
<script context="module">
export async function load({ url }) {
return {
props: {
currentUrl: url.pathname,
},
};
}
</script>
@eladroz
eladroz / svelte.config.js
Last active April 4, 2022 06:56
SvelteKit config with custom Vite plugin
import adapter from '@sveltejs/adapter-netlify';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter(),
vite: {
plugins: [
{
name: 'watch-content',
configureServer(server) {
@eladroz
eladroz / contentfulClient.js
Created April 4, 2022 06:38
Contentful client - polling for updates
import { writeFileSync } from 'fs';
import contentful from 'contentful';
const isDev = process.env.NODE_ENV === 'development';
export const client = contentful.createClient({
accessToken: isDev ? import.meta.env.VITE_CONTENTFUL_PREVIEW_TOKEN :
import.meta.env.VITE_CONTENTFUL_DELIVERY_API_TOKEN,
space: import.meta.env.VITE_CONTENTFUL_SPACE_ID,
host: isDev ? 'preview.contentful.com' : 'cdn.contentful.com'
@eladroz
eladroz / arrow2-graviton2.md
Last active August 12, 2022 06:09
Packaging Apache Arrow 2.0 on AWS Graviton2 (ARM64)

I'm now working on big data processing with Pandas at scale, as a lightweight alternative to Spark. Fortunately, the Apache Arrow project brings with it an excellent and very fast Parquet reader and writer.

With the current push to ARM in both personal computers and the data center, I was curious to check the performance of my code on ARM - running on AWS' homegrown Graviton2 processor. Their c6g instance types are 20% cheaper than the equivalent Intel-based c5's, while promising faster performance. If that's the future, why not start getting ready now?

While there are already Python wheels for NumPy and Pandas, there is no official build yet for PyArrow. There's a pull request in the works,

@eladroz
eladroz / gist:5081492
Last active October 6, 2016 18:14
Graphite aggregation rules for StatsD (excl. for threshold metrics)
#
# These settings are REALLY sensitive! do you feel lucky??
# Consult the documentation for etsy/statsd, but it doesn't have all the info.
#
# Notes:
#
# (a) When determining xFilesFactor, make sure the actual reporting rate would fill enough buckets,
# so that the downsampling won't result in null values.
#
# (b) Up to StatsD v0.5.0, counters are written in two places: