Skip to content

Instantly share code, notes, and snippets.

Working from home

Jebin bvjebin

Working from home
View GitHub Profile
bvjebin / _app.jsx
Last active Oct 4, 2020
Medium article - service worker registration
View _app.jsx
import React from "react";
import App, { Container } from "next/app";
import { Provider } from "react-redux";
import MainLayout from "../components/Layouts/MainLayout";
class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
return {}
bvjebin / service_worker.js
Last active Apr 20, 2019
Medium article - service worker code
View service_worker.js
import * as routing from "workbox-routing";
import * as core from "workbox-core";
import * as strategies from "workbox-strategies";
import * as expiration from "workbox-cache-expiration";
import * as cacheableResponse from "workbox-cacheable-response";
self.addEventListener("sync", function (event) {
console.log("Event from sw: ", event);
self.addEventListener("install", function () {
bvjebin / send_email.ex
Created Aug 31, 2018
send email with bamboo for medium post
View send_email.ex
def send_email(email, csv_path, zip_path) do
attachments = if !is_nil(zip_path) do
attachments = [ | attachments]
new_email(attachments: attachments)
|> subject("Your download is here")
|> from("")
bvjebin / create_zip.ex
Created Aug 31, 2018
Create zip in elixir for medium post
View create_zip.ex
def create_zip(path) do
old_path = File.cwd!! path
:zip.create("", ['images'], [{:cwd, path}])! old_path
bvjebin / export _images_to_zip.ex
Last active Aug 31, 2018
export_images_to_zip for medium post
View export _images_to_zip.ex
def export_images_to_zip(data, path) do
images_to_download =, fn datum ->
%{url: datum.image, name:}
case images_to_download do
[] -> nil
list ->
zip_path = path<>"/images"
:ok = File.mkdir_p!(zip_path)
download_images_in_batch(list, zip_path)
bvjebin / export_to_csv.ex
Last active Aug 31, 2018
Export to csv for medium post
View export_to_csv.ex
def export_to_csv(data, path) do
file_path = path<>"/export.csv"
result =, fn item ->
result = ["Name,Email,Image Url" | result]
File.write!(file_path, Enum.join(result, "\r\n"), [:utf8])
View export_download_zip_email.ex
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
bvjebin / export_email.ex
Last active Aug 31, 2018
handle cast code for medium post
View export_email.ex
@agent :export_email_state
def start_link() do
GenServer.start_link(__MODULE__, %{}, [name: __MODULE__])
Agent.start_link(fn -> end, name: @agent)
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)
bvjebin / user_data.ex
Last active Aug 31, 2018
Example user data for medium post
View user_data.ex
name: "John",
email: "",
image: ""
inserted_at: ~N[2017-10-19 21:22:45.683899],
updated_at: ~N[2017-11-02 14:04:55.616742]
bvjebin / user_controller.ex
Last active Aug 31, 2018
Export API Endpoint
View user_controller.ex
defmodule Example.AdminController do
use Example, :controller
def export(conn, %{"email" => email}) do
|> Example.Export.export_and_email(email)
json(conn, %{
success: true,
message: "Your request is accepted. Data will be emailed shortly"
You can’t perform that action at this time.