Skip to content

Instantly share code, notes, and snippets.

@infinex
infinex / _.md
Created February 11, 2014 04:38
Tributary inlet
@infinex
infinex / hwz_qoo10.r
Last active March 13, 2016 13:11
Extraction of word Cloud in R using tm/rvest/wordcloud
library(rvest)
library(tm)
library(wordcloud)
setwd(paste0(getwd(),'/hwz'))
qoo10<-"http://forums.hardwarezone.com.sg/hardware-clinic-2/qoo10-deals-strictly-no-referral-link-part-2-a-5288313.html"
last_page<-qoo10 %>% read_html() %>% html_nodes(".pagination a") %>% html_attr('href') %>% na.omit(.) %>% strsplit('-') %>% pluck(13,character(1)) %>% gsub(".html","",.) %>% as.numeric %>% max
urls<-vector()
for(i in 1:last_page){
urls[i]<-paste0("http://forums.hardwarezone.com.sg/hardware-clinic-2/qoo10-deals-strictly-no-referral-link-part-2-a-5288313-",i,".html")
@infinex
infinex / intersection_pts_polys.r
Created March 13, 2016 13:06
How to intersect polygons and points in R
library(rgdal)
library(sp)
library(ggplot2)
#you have to supply your own points and polygon
postal_code<-read.csv('postalCode/postal_code.csv')
shape_rgdal <- readOGR("Planning_Area_Census2010", "Planning_Area_Census2010")
shape_rgdal<- spTransform(shape_rgdal , CRS("+proj=longlat +datum=WGS84"))
@infinex
infinex / airport.r
Created March 13, 2016 13:13
Visualisation of airport connectivities in R using ggmap/ggplot/igraph
library(ggmap)
airports <- read.csv(“https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat", header = FALSE)
names(airports) <- c(“id”, “name”, “city”, “country”, “code”,
“icao”, “lat”, “lon”, “altitude”, “timezone”,
“dst”,”tz”)
location <- c( 115,0 )
location
map <- get_map(location, zoom=3,maptype=’toner-lite’)
p <- ggmap(map)
p
@infinex
infinex / gist:66d82da824ebbaef99ea
Created March 13, 2016 13:14
Neo4J Visualization of airport connectivities
LOAD CSV FROM ‘https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat' AS line
CREATE (:Airport { myid:toInt(line[0]),name: line[1], lat: line[6],lon: line[7]})
CREATE INDEX ON :Airport(myid)
LOAD CSV FROM ‘https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat' AS line
MATCH (from:Airport {myid: toInt(line[3])})
MATCH (to:Airport {myid: toInt(line[5])})
MERGE (from)-[r:route]->(to)
ON MATCH SET r.count = r.count + 1 ON CREATE SET r.count = 1
@infinex
infinex / LSTM.py
Last active February 6, 2019 16:15
Simple LSTM with tensorflow eager mode on MNIST
import numpy as np
import tensorflow as tf
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
# Training Parameters
learning_rate = 0.001
@infinex
infinex / siamese_twin.py
Created February 18, 2018 16:55
Siamese Twin Eager Mode Tensorflow Bidirectional LSTM
#BiDirectional LSTM
#Training Data
# Embedding1,Embedding2,Labels
# 1 Jurong,Jurng,1
# 2 Jurong,Jrung,1
# 3 Jurong,Bishan,0
# Purpose: To create measure to determine how similar sequences of inputs are to each other.
import os
import random
@infinex
infinex / gist:88de4b0659cf10b88518c91a2c37c29c
Last active March 12, 2018 16:21
big query date generator
#standard sql
#https://stackoverflow.com/questions/38929121/duplicating-records-to-fill-gap-between-dates-in-google-bigquery
SELECT day
FROM UNNEST(
GENERATE_DATE_ARRAY(
DATE_TRUNC(DATE_SUB(CURRENT_DATE,INTERVAL 1 YEAR),MONTH)
, CURRENT_DATE(), INTERVAL 1 DAY)
) AS day
#standard sql
SELECT "Current Month" as type,cast(TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), MONTH) as date)
UNION ALL
SELECT "Week ending",DATE_ADD(cast(TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), WEEK) as date),interval 7 DAY)
UNION ALL
SELECT "Current Month",DATE_TRUNC(CURRENT_DATE,MONTH)
UNION ALL
SELECT "First day of last Month",DATE_TRUNC(DATE_SUB(CURRENT_DATE,INTERVAL 1 MONTH),MONTH)
UNION ALL
@infinex
infinex / 1.sql
Last active March 12, 2018 16:36
big query rolling average ARPU
WITH
mydate AS(
SELECT
day
FROM
UNNEST( GENERATE_DATE_ARRAY( DATE_TRUNC(DATE_SUB(CURRENT_DATE,INTERVAL 1 YEAR),MONTH), CURRENT_DATE(), INTERVAL 1 DAY) ) AS day ),
randomdata AS(
SELECT
t1.*,
ROUND(t1.revenue*rand()) AS user