Skip to content

Instantly share code, notes, and snippets.

@yuchunc
yuchunc / config
Last active April 7, 2020 04:23
Surfingkeys Config
// an example to create a new mapping `ctrl-y`
mapkey('<Ctrl-y>', 'Show me the money', function() {
Front.showPopup('a well-known phrase uttered by characters in the 1996 film Jerry Maguire (Escape to close).');
});
// an example to replace `T` with `gt`, click `Default mappings` to see how `T` works.
map("K", "R");
map("J", "E");
map("H", "S");
map("L", "D");
@yuchunc
yuchunc / median_sorted_tuple.ex
Last active August 3, 2019 06:06
Leetcode Alogorithm #4 Median of Two Sorted Arrays https://leetcode.com/problems/median-of-two-sorted-arrays/
defmodule MedianSortedTuple do
# NOTE Alogorithm 4
def attempt2(tup1, tup2) do
size1 = tuple_size(tup1)
size2 = tuple_size(tup2)
half_size = (size1 + size2 + 1) |> div(2)
if size1 > size2 do
@yuchunc
yuchunc / median_sorted_tuple_recursion.ex
Last active August 3, 2019 06:04
Leetcode Alogorithm #4 Median of Two Sorted Arrays - Recursion https://leetcode.com/problems/median-of-two-sorted-arrays/
# NOTE this is a failed attempt
defmodule MedianSortedTuple do
# NOTE Alogorithm 4
def find({}, {}), do: 0
def find(tup1, tup2) do
full_size = tuple_size(tup1) + tuple_size(tup2)
@yuchunc
yuchunc / combine_interval.exs
Last active July 24, 2019 14:18
Grindr Interview Question
defmodule CombineInterval do
def merge_interval([]), do: []
def merge_interval([h | t]), do: merge_interval(t, [h])
def merge_interval([], acc), do: Enum.reverse(acc)
def merge_interval([h | t], acc = [acc_h | acc_t]) do
{start, _leng} = h
{acc_h_start, acc_h_leng} = acc_h
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
{:ok, user} = Account.fb_auth(auth.uid, auth.info)
Streaming.find_or_create_channel(user)
conn
|> Guardian.Plug.sign_in(user)
|> put_flash(:success, "Signed In!")
|> redirect(to: "/")
end

Keybase proof

I hereby claim:

  • I am yuchunc on github.
  • I am mickeychen (https://keybase.io/mickeychen) on keybase.
  • I have a public key ASCNsnzV1ahcwLeWs-iFVGJ4ewSMGbCLn7iUTiGgAJ3X-wo

To claim this, I am signing this object:

year=$(date +%Y)
month=$(date +%m)
date=$(date +%Y-%m-%d)
j_dir="~/Dropbox/daily_journal/$year/$month"
j_file="~/Dropbox/daily_journal/$year/$month/$date"
alias wj="mkdir -p $j_dir && cp ~/Dropbox/daily_journal/template $j_file && vim $j_file"
@yuchunc
yuchunc / file_organizer.sh
Created July 10, 2016 01:30
Shell Script File Organization
#!/bin/zsh
UNSORTED_DIR=./sample_files/*
MEMORIA_DIR=./memoria
OTHER_DIR=./other_files
image_formats="jpg|jpeg|jif|jfif|jp2|jpx|j2k|j2c|tif|gif|pfx|pcd|png"
video_formats="3g2|3gp|asf|avi|flv|m4v|mov|mp4|mpg|rm|srt|swf|vob|wmv"
for some_file in $UNSORTED_DIR
# Directly copied from eycap-0.5.2 (thanks!)
#
# With these tasks you can:
# - dump your production database and save it in shared_path/db_backups
# - dump your production into your local database (clone_to_local)
#
# Tested and fixed by fjguzman
Capistrano::Configuration.instance(:must_exist).load do
namespace :db do
select DATE_FORMAT(time_period ,'%Y-%m-%d') as date,
sum(CASE WHEN EXTRACT(hour from time_period) = 00 THEN unique_visitors ELSE 0 END) as '00',
sum(CASE WHEN EXTRACT(hour from time_period) = 01 THEN unique_visitors ELSE 0 END) as '01',
sum(CASE WHEN EXTRACT(hour from time_period) = 02 THEN unique_visitors ELSE 0 END) as '02',
sum(CASE WHEN EXTRACT(hour from time_period) = 03 THEN unique_visitors ELSE 0 END) as '03',
sum(CASE WHEN EXTRACT(hour from time_period) = 04 THEN unique_visitors ELSE 0 END) as '04',
sum(CASE WHEN EXTRACT(hour from time_period) = 05 THEN unique_visitors ELSE 0 END) as '05',
sum(CASE WHEN EXTRACT(hour from time_period) = 06 THEN unique_visitors ELSE 0 END) as '06',
sum(CASE WHEN EXTRACT(hour from time_period) = 07 THEN unique_visitors ELSE 0 END) as '07',
sum(CASE WHEN EXTRACT(hour from time_period) = 08 THEN unique_visitors ELSE 0 END) as '08',