Skip to content

Instantly share code, notes, and snippets.

@python273
python273 / app.py
Last active April 19, 2024 11:05
Flask Streaming Langchain Example
import os
os.environ["OPENAI_API_KEY"] = ""
from flask import Flask, Response, request
import threading
import queue
from langchain.chat_models import ChatOpenAI
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.schema import AIMessage, HumanMessage, SystemMessage
@imartinezl
imartinezl / eurostat_data.R
Created October 5, 2019 12:49
Eurostat data: density and fertility maps
# Geographical Data -------------------------------------------------------
library(dplyr)
# download geospatial data for NUTS-3 regions
euro_nuts3_sf <-
eurostat::get_eurostat_geospatial(output_class = 'sf', resolution = '60', nuts_level = 3) %>%
sf::st_transform(crs = 3035)
library(eurostat) # eurostat data
library(rnaturalearth) # worldwide map data
library(tidyverse) # tidy data transformation
library(lubridate) # date and time support
library(sf) # simple features GIS
euro_pop <-
get_eurostat('demo_r_pjanaggr3', stringsAsFactors = FALSE) %>%
filter(
str_length(geo) == 5, # NUTS-3
@k5cents
k5cents / uk_coalpower.R
Last active May 28, 2019 00:26 — forked from cavedave/coalpower.r
Visualizing UK Coal Usage (Simplified Code)
# this script automates the collection, processing, and plotting of gridwatch energy data
# 2019-05-27
# @kiernann
# u/WannabeWonk
# install.packages("pacman")
pacman::p_load(
RSelenium,
readr,
dplyr,
@furbrain
furbrain / bearable.py
Last active February 15, 2018 16:49
Hacking the bearable
import smbus
import time
DEV_ADDRESS = 0x15
class Bearable():
def __init__(self):
self.bus=smbus.SMBus(1)
self.leds = [0]*12
@schochastics
schochastics / storms.R
Created September 5, 2017 11:36
replication of u/Tjukanov's post in r/dataisbeautiful in R
################################################################################
# replication of https://i.redd.it/q0udc4wfhvjz.gif
# originally posted to r/dataisbeautiful by u/Tjukanov
################################################################################
library(tidyverse)
library(gganimate)
library(lubridate)
#data from: https://www.ncdc.noaa.gov/ibtracs/index.php?name=wmo-data
df <- read_csv("Allstorms.ibtracs_wmo.v03r09.csv")
@ikashnitsky
ikashnitsky / NEET-in-Europe.R
Last active January 24, 2018 05:14
Young people neither in employment nor in education and training in Europe, 2000-2016
################################################################################
#
# ikashnitsky.github.io 2017-07-18
# Accessing Eurostat data using the `eurostat` R package
# Young people neither in employment nor in education and training in Europe
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#
################################################################################
library(tidyverse)
@halhen
halhen / codes.csv
Last active February 18, 2024 22:49
The people who keep us company - dataviz
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 1 column, instead of 2. in line 7.
code;name
01;Personal Care Activities
0101;Sleeping
0102;Grooming
0103;Health-related self care
0104;Personal Activities
0105;Personal Care Emergencies
0199;Personal care, n.e.c.*
02;Household Activities
0201;Housework
library(tidyverse)
library(stringr)
# read in the transcript
# I simply copied the text from the page at
# https://www.washingtonpost.com/news/the-fix/wp/2016/09/26/the-first-trump-clinton-presidential-debate-transcript-annotated/
# and popped it into a txt file
xx <- scan("first_debate_2016.txt", "character")
@jebyrnes
jebyrnes / had_crut_spider_plot.R
Created May 13, 2016 18:40
R code to reproduce the awesome visualization of global temperature change from Ed Hawkins at http://www.climate-lab-book.ac.uk/2016/spiralling-global-temperatures/ using R and ggplot2 (with the animations package)
library(dplyr)
library(tidyr)
library(ggplot2)
library(animation)
#Data from https://crudata.uea.ac.uk/cru/data/temperature/
#As well as data read in script
source("read_cru_hemi.R")
temp_dat <- read_cru_hemi("./HadCRUT4-gl.dat")
#remove cover