Skip to content

Instantly share code, notes, and snippets.

View john012343210's full-sized avatar
💭
LearnAsManyAsIcan

Nameeeee john012343210

💭
LearnAsManyAsIcan
View GitHub Profile
@john012343210
john012343210 / answer1.py
Created November 9, 2018 12:07
Check whether the alphabetical array is a subset of another alphabetical array. RUNNING TIME O(n)
import string
def isSubset(arr1,arr2):
d = dict.fromkeys(string.ascii_lowercase, 0)
for i in arr1:
d[i]+=1
for j in arr2:
if d[j] == 0:
return False
@john012343210
john012343210 / answer2.md
Created November 9, 2018 12:10
RUNNING TIME ANALYSIS

let the len of first array be n

it run in O(n)

create 26 letter array cost is constant, count the occuance of each letter in array1 is O(n) check whether the element in array2 is indeed in array1 is O(n)

Totally O(n)

@john012343210
john012343210 / answer3.py
Created November 10, 2018 16:07
calculate the nearest fibonacci numbers for each element in array with O(n) with n being the size of input
from math import sqrt,log,ceil
def fibo(n):
return int((((1+sqrt(5))**n)-((1-sqrt(5))**n))/((2**n)*sqrt(5)))
def nearestFibo(array):
for k in array:
larger_Nearest_Fibo = ceil( (log(sqrt(5)*k)) /(log((1+sqrt(5))/2)) )
print(fibo(larger_Nearest_Fibo))

the problem is that the variable i, within each of the inside anonymous functions, is bound to the same variable outside of the function.

we could just do this

function createfunc(k) { return function(i) { return i+k; }; }

function createArrayOfFunctions(y){

@john012343210
john012343210 / test.py
Created August 5, 2020 23:34
Getting repositories information of a user using github api v4
QUERY="""
query {
user(login:"AronWater") {
repositories(last:100) { ######### putting 100 here might generate timeout error
totalCount
totalDiskUsage
pageInfo {
endCursor
hasNextPage
@john012343210
john012343210 / test.py
Last active August 6, 2020 00:31
Getting repositories information of a user using github api v4
QUERY="""
query {
user(login:"YOURUSERNAME_HERE") {
repositories(last:100) { ######### putting 100 here might generate timeout error
totalCount
totalDiskUsage
pageInfo {
endCursor
hasNextPage
@john012343210
john012343210 / bugReport
Created December 6, 2020 14:50
BugReportApiV4
query {
user(login:"AronWater") {
repositories(first:1,after:null)
{
totalCount
totalDiskUsage
pageInfo {
endCursor
hasNextPage
hasPreviousPage
@john012343210
john012343210 / mirror_all_githubRepo_to_Gitlab.MD
Last active February 24, 2021 01:46
sync github to gitlab
  • proposal:
    • doesnt use gitlab pull mirror or github action to push
      • approach 0: a script in a server periodically pulling the change from all github repo to local from github and pushing to gitlab.
        • problems
          • required the server to be always running, and it has to contains all the github repos in drive.
    • use gitlab pull mirror:
      • approach 1: when you create a new repo in GitHub, the webhook is sent to a script that could create a GitLab repo, and then setup the mirror
        • problems
          • there is no API to configure the pull mirror in gitlab, so it couldn't be automated.
  • [existing feature request]
@john012343210
john012343210 / D3JS Tree Editor.md
Created February 26, 2021 02:08 — forked from adamfeuer/ D3JS Tree Editor.md
d3js tree editor with node create, delete, and rename
We couldn’t find that file to show.