Skip to content

Instantly share code, notes, and snippets.

View tuxdna's full-sized avatar

Saleem Ansari tuxdna

View GitHub Profile
@tuxdna
tuxdna / README.md
Created February 9, 2018 07:01
Why software estimation fails?
@tuxdna
tuxdna / closest_pair2d.py
Last active February 8, 2018 14:11
Some coding problems
# find closest pair of points in 2d space in O(nlogn)
import sys
import math
def euclidean_distance(p1, p2):
x1, y1 = p1
x2, y2 = p2
return math.sqrt((x2-x1)**2 + (y2 - y1)**2)
@tuxdna
tuxdna / README.md
Last active February 3, 2018 21:05
Estimating n log n via a estimation like newtons method

Estimating hard to invert functions

Works for

  • n log(n)
  • n! ( Factorial function )
$ python function_estimation.py 
@tuxdna
tuxdna / README.md
Last active March 7, 2018 10:11
Sync graph data

How to run?

Create config.py from config.py.template and fill in your AUTH token, and the target URL.

Then invoke the grpah sync:

$ python3 perform_graph_sync.py package input-file.json maven

Invoking url: http://.../api/v1/graphsync/sync_all/maven/HTTPClient%3AHTTPClient
@tuxdna
tuxdna / readme.md
Created November 26, 2017 14:07
Create portable encrypted filesystem

Create a disk file with random data

$ truncate -s 50G encrypted_backup.disk

Setup encryption for that device file

$ cryptsetup --verbose --verify-passphrase -s 512 luksFormat encrypted_backup.disk
@tuxdna
tuxdna / go_ecosystem_graph.json
Created November 7, 2017 15:38
Go ingestion in staging
{
"requestId": "d3c056d7-428e-42f8-ba43-cbc0e1413970",
"status": {
"message": "",
"code": 200,
"attributes": {}
},
"result": {
"data": [
{
@tuxdna
tuxdna / readme.md
Last active November 15, 2017 12:27
One project - multiple dependency versions of the same package
$ find . -name requirements.txt -exec ls "{}" \; 
./integration-tests/data/requirements.txt
./integration-tests/requirements.txt
./dashboard/requirements.txt
./fabric8-analytics-firehose-fetcher/requirements.txt
./fabric8-analytics-firehose-fetcher/integration_tests/requirements.txt
./fabric8-analytics-license-analysis/requirements.txt
./fabric8-analytics-tagger/requirements.txt
./perf-tests/requirements.txt
@tuxdna
tuxdna / go-ingest.md
Created October 31, 2017 12:07
None version appearing in one dependency

http://localhost:32000/api/v1/component-analyses/go/github.com%2fgorilla%2fmux/master

data-model-importer_1   | --------------------------------------------------------------------------------
data-model-importer_1   | INFO in rest_api [/src/rest_api.py:80]:
data-model-importer_1   | Selective Ingestion with payload - {"select_ingest": ["libraries_io", "git_stats"], "package_list": [{"ecosystem": "go", "version": null, "name": "github.com/gorilla/context"}]}
data-model-importer_1   | --------------------------------------------------------------------------------
data-model-importer_1   | --------------------------------------------------------------------------------
data-model-importer_1   | INFO in rest_api [/src/rest_api.py:88]:
@tuxdna
tuxdna / go-ingestion-docs.md
Created October 18, 2017 11:01
gofedlib vs go list

Document describing what kind of dependencies go list reports, and whether or not it satisfies the requirements of ingestion.

An alternative approach ( as suggested on mailing list) could be to use go list command line tool to find all the dependencies of a Go project.

For example:

$ go get github.com/mattermost/platform
$ go list -f="{{.ImportPath}} {{.Imports}}" github.com/mattermost/platform | python2 -c 'import sys; import re; import json; print json.dumps({x[0]: x[1] for x in map(lambda s: (re.match("(\S+)\s\[(.*?)\]", s).groups()[0], re.match("(\S+)\s\[(.*?)\]", s).groups()[1].split()), sys.stdin.readlines())})'  | python -mjson.tool
@tuxdna
tuxdna / top_go_packages.py
Created October 18, 2017 09:56
Enlist top Go packages
import requests
import functools
# data = json.load(open("top-go-packages.json"))
r = requests.get("http://go-search.org/api?action=tops&len=100")
data = r.json()
kinds = [d for d in data if d["Name"] != "Sites"]
concatenated = functools.reduce(lambda x, y: x + y["Items"], kinds, [])
top_list = sorted(set([(x["Name"], x["Package"]) for x in concatenated]))
for i,d in enumerate(top_list):