Skip to content

Instantly share code, notes, and snippets.

View richardoey's full-sized avatar
🎯
Focusing

richardoey richardoey

🎯
Focusing
View GitHub Profile
@richardoey
richardoey / CouchDB Snippet Replicaation Command
Created March 7, 2018 03:12
1. replication from local to server (or anything else)
curl -H 'Content-Type: application/json' -X POST http://localhost:5984/_replicate -d ' {"source": "http://localhost:5984/bec-ember-three/", "target": "http://128.199.160.40:5984/bec-ember-recover"}'
curl -X POST http://128.199.160.40:5984/_replicate -H "Content-Type: application/json" -d '{"source": "test_database", "target":"bec-practice", "doc_ids": ["practices"]}'
@richardoey
richardoey / answer1.py
Last active March 18, 2019 12:32
Question 1 (Write a function that takes two arrays as input, each array contains a list of A-Z; Your program should return True if the 2nd array is a subset of 1st array, or False if not.)
def isSubset(arr1, arr2):
count = 0
flagSubset = False
for i in range(len(arr2)):
for j in range(len(arr1)):
if(arr2[i].strip().upper() == arr1[j].strip().upper()):
count+=1
break
@richardoey
richardoey / answer2.md
Last active March 18, 2019 12:33
Question 2 (What is the computational complexity of your answer in Question 1? Can you explain why?)

Answer 2
What is the computational complexity of your answer in Question 1? Can you explain why?

The computational complexity of Question 1 is O(n2).

Explanation:

for i in range(len(arr2)):
@richardoey
richardoey / answer3.py
Last active March 21, 2019 15:53
Question 3 (Write a function that takes an array of integers as input. For each integer, output the next fibonacci number. Solution that work both cpu and memory efficient are appreciated.)
import time
def recursiveFibonacci(number, fn1, fn2):
fnNext = fn1 + fn2
fn1 = fn2
if number < fnNext:
print(fnNext)
else:
recursiveFibonacci(number, fn1,fnNext)
@richardoey
richardoey / answer4.js
Last active March 21, 2019 16:56
Question 4 (Please explain what is the bug in the following Javascript function, and how to correct it.)
function createArrayOfFunctions(y){
var arr = [];
x = 1
for (let i = 0; i < y ; i++){
arr[i] = function(x){
return x + i;
}
}
return arr;
@richardoey
richardoey / index.html
Last active December 7, 2020 09:32
read csv file data in Django
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta name="viewport" content="width=device-width" />
<title>ATE-Dashboard</title>
@richardoey
richardoey / projects.py
Created December 9, 2020 06:41
How to iterate through dict in Django template
{% for key, value in test_codes_dict.items %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
@richardoey
richardoey / git-pushing-multiple.rst
Created February 23, 2021 05:39 — forked from rvl/git-pushing-multiple.rst
How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.

Pushing to Multiple Git Repos

If a project has to have multiple git repos (e.g. Bitbucket and Github) then it's better that they remain in sync.

Usually this would involve pushing each branch to each repo in turn, but actually Git allows pushing to multiple repos in one go.

If in doubt about what git is doing when you run these commands, just

@richardoey
richardoey / Delete Files when Deleting Models Django
Last active March 9, 2021 03:58
Django basically doesn't delete the associate file in the model you delete. In order to automatically delete all the file when model is delete, put below code inside the models.py.
from django.db.models.signals import post_delete, pre_save
from django.dispatch import receiver
from django.db import models
""" Whenever ANY model is deleted, if it has a file field on it, delete the associated file too"""
@receiver(post_delete)
def delete_files_when_row_deleted_from_db(sender, instance, **kwargs):
for field in sender._meta.concrete_fields:
if isinstance(field,models.FileField):
instance_file_field = getattr(instance,field.name)
@richardoey
richardoey / workflow.md
Created March 16, 2021 06:14
Workflow working while waiting for pending PR

Preferred workflow for this:

  1. On branch master, git checkout -b user_story_1.
  2. Make changes to user_story_1.
  3. Open PR for user_story_1.
  4. On branch user_story_1, git checkout -b user_story_2.
  5. Make changes to user_story_2.
  6. Once user_story_1 gets merged into master, switch to user_story_2 and do git rebase -i master.
  7. This should show you a list of commits on user_story_2 that you want to include in the rebase. Delete the top few commits that came from user_story_1.
  8. The rebase should complete cleanly unless master was updated with other changes. Now you have user_story_2 rebased on master and only having its commits.