Skip to content

Instantly share code, notes, and snippets.

View paramsingh's full-sized avatar

param paramsingh

View GitHub Profile
Error: (psycopg2.ProgrammingError) syntax error at or near "\"
LINE 1: \set ON_ERROR_STOP 1
^
[SQL: '\\set ON_ERROR_STOP 1']
Traceback (most recent call last):
File "manage.py", line 164, in <module>
cli()
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 664, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 644, in main
@paramsingh
paramsingh / plan.md
Last active February 12, 2017 11:06
Listenbrainz Stats work.

Last.fm currently shows top artists, top albums and top tracks on the user page, with the flat list of listens that ListenBrainz already has. On artist and album pages, it shows top listeners and top tracks prominently.

There is an idea on the GSoC 2017 page for this already, but right now it only involves generation of user stats with no mention of artists etc. I propose that we add artist and album pages to the idea also, before breaking it into two parts, the first of which I'll work on before summer and the second of which will involve a GSoC student (hopefully me) continuing on the work already done.

API KEY: 4ee906c88901bf69ddaf7fdc4112d50d
Shared Secret cb814159047954261e7f2c19193befb7
2017-02-02 15:40:46,376 INFO Connecting to redis: redis
2017-02-02 15:40:46,377 INFO Connecting to postgresql: postgresql://listenbrainz:listenbrainz@db:5432/listenbrainz
DROP DATABASE
DROP ROLE
Creating database and user for testing...
CREATE ROLE
CREATE DATABASE
CREATE EXTENSION
Create influx test database...
/code/listenbrainz/admin/influx/create_test_db.py
a = 3
if a == 1:
print(a)
elif a == 2:
print(a)
else:
print("hello", "2")
if a == 2 and a == 3:
print("hi")
import time
import requests
api_key = 'APIKEY'
api_sig = 'fdjakl'
payload = {'api_key': api_key, 'api_sig': api_sig}
x = payload.copy()
x['token'] = token
x['sk'] = sk
x['method'] = 'track.scrobble'
x['artist[0]'] = 'Drake'

GCD Extended Euclid

// finds gcd of a and b
// and puts solution of ax + by = gcd(a, b)
// into x and y
int gcd (int a, int b, int & x, int & y) {
    if (a == 0) {
        x = 0; y = 1;
        return b;

}

import requests
import json
import time
USER_TOKEN = "token <user_token>" # <user_token> contains my user token in the code that i'm running
url = 'https://api.listenbrainz.org/1/submit-listens'
# get data from test json file
tosend = json.load(open("test.json"))
tosend["payload"]["listened_at"] = int(time.time()) # add listened at
print(json.dumps(tosend))
@paramsingh
paramsingh / hashing.md
Created October 4, 2016 10:34
hashing

Hashing Algorithms in online tasks

Hashing Algorithms are helpful in solving a lot of problems. But they have a big flaw that sometimes they are not 100% deterministically correct because when there are plenty of strings, hashes may collide. However, in the majority of tasks this can be ignored, since the probability of the hashes of two different string colliding is still very small.

Determination of the hash and its calculation

One of the best ways to determine the hash of a string S is the following function:

$ hash(S) = S[0] + S[1] * P + S[2] * P ^ 2 + S[3] * P ^ 3 + ... + S[N] * P ^ N $

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<char, pair<int, int> > edge;
struct rule {
char left;
vector<char> right;
} rules[10];