Skip to content

Instantly share code, notes, and snippets.

View albertyumol's full-sized avatar
:octocat:
just bash-ing around

Albert 'Bash' Yumol albertyumol

:octocat:
just bash-ing around
  • Manila, Philippines
View GitHub Profile
@albertyumol
albertyumol / Edge_Detection.asc
Created March 4, 2019 02:21
Area estimation using Green's Theorem and Edge Detection Algorithm in Scilab.
//Opens the image to be processed
Circle = imread('C:\Users\csrc-lab03\Desktop\yakal5.bmp');
Circle = rgb2gray(Circle)
//Use edge() function sobel
edge_sobel = edge(Circle,'canny');
imshow(edge_sobel);
imwrite(edge_sobel,'Circle_sobel.bmp');
//Edge pixel coordinates
@albertyumol
albertyumol / gdelt_bigQ.sql
Created September 30, 2019 03:11
Big Query for event logs for news in the Philippines since year 2000
select SQLDATE, MonthYear, EventRootCode, GoldsteinScale, NumMentions, AvgTone, ActionGeo_CountryCode, ActionGeo_Lat, ActionGeo_Long
from `gdelt-bq.full.events`
where
SQLDATE > 20000101 and
ActionGeo_CountryCode = 'RP';
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import matplotlib.pyplot as plt
from matplotlib.cm import ScalarMappable
from mpl_toolkits.basemap import Basemap
from matplotlib.animation import FuncAnimation
### Create a figure and draw a basemap
fig, ax = plt.subplots(figsize=(10,8), dpi=500)
m = Basemap(resolution='h',
import pandas as pd
import numpy as np
### Read in county data and drought info data
dr = pd.read_csv('rallies.csv')
dr1 = dr[['event_date', 'event_type', 'latitude', 'longitude', 'location']]
### Data cleansing
dr1.event_date = pd.to_datetime(dr1.event_date)
num_m = len(dr.event_date.unique())
### Set county location values, drough level values, marker sizes (according to county size), colormap and title
x, y = m(dr_m.nth(0).longitude.tolist(), dr_m.nth(0).latitude.tolist())
colors = (dr_m.nth(0).code).tolist()
sizes = (dr_m.nth(0).count1*80).tolist()
cmap = plt.cm.plasma#autumn_r
#cmap = plt.cm.hot_r
sm = ScalarMappable(cmap=cmap)
plt.title('Social Movement (Year-Month): '+dr_m.nth(0).event_date.iloc[0].strftime('%Y-%m'))
### Display the scatter plot and its colorbar (0-5)
@albertyumol
albertyumol / mean.py
Created October 21, 2019 23:00
Calculating mean in Python.
#assuming that x is a list of values and is not empty
#because we are not allowed to divide by 0
def mean(x):
return sum(x) / len(x)
@albertyumol
albertyumol / median.py
Created October 22, 2019 02:08
Calculating mean in Python.
def median(x):
sorted_ = sorted(x)
N = len(x)
middle_value = N // 2
if n % 2 != 0: #CASE 1: if N is odd
M = sorted_[middle_value]
else: #CASE 2: if N is odd
M = (sorted_[(middle_value) - 1] + sorted_[middle_value]) / 2
return M
@albertyumol
albertyumol / eskwelabs_exam_scores.py
Created October 22, 2019 03:00
Distribution of Scores from the Eskwelabs Entrance Exam
import random
import pandas as pd
import matplotlib.pyplot as plt
random.seed( 30 ) #for replicability
n = 100
y = []
for i in range(n):
y += [random.randint(25, 50)]