Skip to content

Instantly share code, notes, and snippets.

View bvjebin's full-sized avatar
🎯
Focusing

Jebin bvjebin

🎯
Focusing
View GitHub Profile
@bvjebin
bvjebin / geojson.js
Last active August 29, 2015 14:01
dummy geojson
window.geojson = {"type":"Topology","objects":{"counties":{"type":"GeometryCollection","bbox":[-179.1473399999999,17.67439566600018,179.7784800000003,71.38921046500008],"geometries":[{"type":"MultiPolygon","id":53073,"arcs":[[[0,1,2]]]},{"type":"Polygon","id":30105,"arcs":[[3,4,5,6,7,8]]},{"type":"Polygon","id":30029,"arcs":[[9,10,11,12,13,14,15,16,17,18]]},{"type":"Polygon","id":16021,"arcs":[[19,20,21,22]]},{"type":"Polygon","id":30071,"arcs":[[-8,23,24,25,26,27]]},{"type":"Polygon","id":38079,"arcs":[[28,29,30,31]]},{"type":"Polygon","id":30053,"arcs":[[-18,32,33,-20,34]]},{"type":"Polygon","id":38009,"arcs":[[-30,35,36,37,38]]},{"type":"Polygon","id":30035,"arcs":[[39,40,-10,41]]},{"type":"Polygon","id":30041,"arcs":[[42,43,44,45]]},{"type":"Polygon","id":30005,"arcs":[[-27,46,47,-46,48]]},{"type":"Polygon","id":30019,"arcs":[[49,50,-4,51]]},{"type":"Polygon","id":38067,"arcs":[[52,53,54,55]]},{"type":"Polygon","id":27069,"arcs":[[56,57,-53,58]]},{"type":"Polygon","id":38095,"arcs":[[59,60,61,-32,62,63]]}
@bvjebin
bvjebin / index.html
Created November 5, 2014 06:28
Two column - one flexible - one fixed width layout
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<header>
Two column layout with right column taking fixed width and rest to be occupied by the left column
</header>
/**
* FileName: phoenix.js
*
* Module Name: phoenix
*
* Created By: jebin
*
* Created at: 17/01/16
*
* Description: Copied from phoenix framework - deps/phoenix/priv/static/phoenix.js
//Login to your Uber and run the below code in your console.
//It will output how much have you spent from the given date to today on cabs.
//It excludes UberEATS
var result = [], total = 0, start_date = new Date("04-01-2017").getTime();
function url(page) {
return "https://riders.uber.com/trips?page="+page;
}
function Ajax(options) {
var url = options.url,
method = options.method || "GET",
@bvjebin
bvjebin / user_controller.ex
Last active August 31, 2018 10:30
Export API Endpoint
defmodule Example.AdminController do
use Example, :controller
def export(conn, %{"email" => email}) do
Example.User.get_dump()
|> Example.Export.export_and_email(email)
json(conn, %{
success: true,
message: "Your request is accepted. Data will be emailed shortly"
})
@bvjebin
bvjebin / export_email.ex
Last active August 31, 2018 11:33
handle cast code for medium post
@agent :export_email_state
def start_link() do
GenServer.start_link(__MODULE__, %{}, [name: __MODULE__])
Agent.start_link(fn -> Map.new end, name: @agent)
end
def handle_cast({:export_email, {data, email}}, state) do
key = email
job_status = Agent.get(@agent, fn agent_state -> Map.get(agent_state, key) end)
def export_download_zip_email(data, email) do
tmp_folder_name = "users_"<>Random.random_string(8)
path = File.cwd!<>"/tmp/"<>tmp_folder_name
:ok = File.mkdir_p!(path)
csv_path = export_to_csv(data, path)
download_images(data, path)
zip_path = create_zip(data, path)
send_email(email, csv_path, zip_path)
File.rm_rf path
end
@bvjebin
bvjebin / export_to_csv.ex
Last active August 31, 2018 12:18
Export to csv for medium post
def export_to_csv(data, path) do
file_path = path<>"/export.csv"
result = Enum.map(data, fn item ->
"#{item.name}\",#{item.email},\"#{item.image}"
end)
result = ["Name,Email,Image Url" | result]
File.write!(file_path, Enum.join(result, "\r\n"), [:utf8])
file_path
end
@bvjebin
bvjebin / user_data.ex
Last active August 31, 2018 12:45
Example user data for medium post
[
%Example.User{
name: "John",
email: "john@example.com",
image: "https://images.example.com/uploads/eaa88003-fa4e-4ba7-afb1-787dcdea72af.jpg"
inserted_at: ~N[2017-10-19 21:22:45.683899],
updated_at: ~N[2017-11-02 14:04:55.616742]
}
]
@bvjebin
bvjebin / export _images_to_zip.ex
Last active August 31, 2018 13:32
export_images_to_zip for medium post
def export_images_to_zip(data, path) do
images_to_download = Enum.map(data, fn datum ->
%{url: datum.image, name: datum.name}
end)
case images_to_download do
[] -> nil
list ->
zip_path = path<>"/images"
:ok = File.mkdir_p!(zip_path)
download_images_in_batch(list, zip_path)