Skip to content

Instantly share code, notes, and snippets.

View lc0's full-sized avatar

Sergii Khomenko lc0

View GitHub Profile
net = await async function () {
console.log('Loading the mobilenet model..');
var _net = await mobilenet.load();
console.log('Sucessfully loaded model');
return _net;
}();
@lc0
lc0 / census_aging.R
Last active February 28, 2016 21:40
R visualisation of a country aging based on Census data
library(idbr) # devtools::install_github('walkerke/idbr')
library(ggplot2)
library(animation)
library(dplyr)
library(ggthemes)
idb_api_key("Your Census API key goes here")
male <- idb1('JA', 2010:2050, sex = 'male') %>%
mutate(POP = POP * -1,
@lc0
lc0 / butterfly.R
Last active August 29, 2015 14:27
Nice visualisation with R and ggplot2
library(ggplot2)
npoints = 500
npointsb = 1200
opt = theme(legend.position="none",
panel.background = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
axis.text = element_blank())
@lc0
lc0 / fivethirtyeight.R
Last active August 29, 2015 14:05
FiveThirtyEight ggplot2 styles
library(ggplot2)
library(grid)
line1 <- rnorm(100,mean=15-seq(1,6,by=.05),sd=1)
line2 <- rnorm(100,mean=4+seq(1,21,by=.2),sd=.5)
time <- seq(1,100,by=1)
data <- data.frame(time,line1,line2)
ggplot(data,aes(time)) +
# The actual lines
function search_all(fullst, substr)
c = 0
a = search(fullst, substr)
while size(a) > (0,)
c += 1
a = search(fullst, substr, a[1] + 1)
end
return c
@lc0
lc0 / mysql.go
Last active December 31, 2015 15:39
friendly querying of data in Go
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
import.packages <- function(pkg) {
if (!require(pkg, character.only=TRUE)) {
install.packages(pkg, dep=TRUE)
require(pkg, character.only=TRUE)
}
}
ip2coordinates <- function(ip, session=getCurlHandle()) {
api <- "http://www.datasciencetoolkit.org/ip2coordinates/"
get.ips <- getURL(paste(api, URLencode(ip), sep=""), curl=session)
@lc0
lc0 / fixes.diff
Last active March 12, 2022 18:40
Fixed version of twitterMap.R by Simply Statistics Blog. Fixed because currently you need oAuth to query user data. More details here http://lc0.github.io/blog/2013/08/25/twitter-word-cloud-with-r/
--- from_file
+++ untitled 2
@@ -77,16 +77,16 @@
# Get location data
cat("Getting data from Twitter, this may take a moment.\n")
- tmp = getUser(userName, cainfo="cacert.pem")
+ tmp = getUser(userName)
if(is.null(userLocation)){
userLocation = location(tmp)
@lc0
lc0 / OAuthFactory.R
Created August 24, 2013 21:16
Simple way to build twitter word cloud
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
consumerKey <- 'consumerKey'
consumerSecret <- 'consumerSecret'
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
@lc0
lc0 / exercise3.R
Last active December 16, 2015 07:09
Data analysis with R. Workshop @ NoSQL RoadShow Munich
# Training: Big Data Analyses with R
# Exercise 3
Sys.setenv(HADOOP_CMD="/usr/bin/hadoop")
Sys.setenv(HADOOP_STREAMING="/usr/lib/hadoop-0.20-mapreduce/contrib/streaming/hadoop-streaming-2.0.0-mr1-cdh4.2.0.jar")
library(rmr2)
input <- to.dfs(1:1000)
out <- mapreduce(
input = input,
map = function(k, v) cbind(v, v^2))