Skip to content

Instantly share code, notes, and snippets.

View satwikkansal's full-sized avatar

Satwik Kansal satwikkansal

View GitHub Profile
@satwikkansal
satwikkansal / request_ranking.py
Last active March 22, 2016 20:01
Ranking of exploration request for oppia
from datetime import datetime, timedelta
from math import log
epoch = datetime(1970, 1, 1)
def epoch_seconds(date):
td = date - epoch
return td.days * 86400 + td.seconds + (float(td.microseconds) / 1000000)
@satwikkansal
satwikkansal / scrape.py
Last active June 18, 2016 13:51
Fetching the content
import requests
response = requests.get('https://in.pycon.org/cfp/2016/proposals/')
if response.status_code == 200:
print "Fetched the page sucessfully"
print response.content
@satwikkansal
satwikkansal / scrape.py
Created June 27, 2016 12:22
Scraping top Stackoverflow posts using Scrapy
import scrapy
class Stackoverflowspider(scrapy.spider):
name = 'stackoverflow'
start_urls = ['http://stackoverflow.com/questions?sort=votes']
def parse(self, response):
for href in response.css('.question-summary h3 a::attr(href)'):
full_url = response.urljoin(href.extract())
yield scrapy.Request(full_url, callback=self.parse_question)
def parse_question(self, response):
yield {
import time
import random
import datetime
import telepot
"""
After **inserting token** in the source code, run it:
```
$ python2.7 diceyclock.py
```
@satwikkansal
satwikkansal / README.md
Last active August 11, 2017 16:59
Github README.rst and README.md styles
@satwikkansal
satwikkansal / snippet.cs
Created May 2, 2018 19:36
Creating persistent menu and get started button in C# (useful for ASP.net)
// Snippet for persistent menu
var client = new RestClient("https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "2f9a47e2-2a8a-0a70-c4ce-cb72dbfd8e93");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\n \"setting_type\" : \"call_to_actions\",\n \"thread_state\" : \"existing_thread\",\n \"call_to_actions\":[\n {\n \"type\":\"postback\",\n \"title\":\"Help\",\n \"payload\":\"DEVELOPER_DEFINED_PAYLOAD_FOR_HELP\"\n },\n {\n \"type\":\"postback\",\n \"title\":\"Start a New Order\",\n \"payload\":\"DEVELOPER_DEFINED_PAYLOAD_FOR_START_ORDER\"\n },\n {\n \"type\":\"web_url\",\n \"title\":\"View Website\",\n \"url\":\"http://petersapparel.parseapp.com/\"\n }\n ]\n }", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
@satwikkansal
satwikkansal / oss_2k18.md
Last active June 22, 2018 12:02
GSoC Discussion (intermediate)
@satwikkansal
satwikkansal / REPORT.md
Last active March 29, 2019 13:14
Work Report for Google Summer Of Code 2017
Orgainization [coala]
Project name Enhance coala-quickstart
Primary repository [coala-quickstart]
Project Mentors Adhityaa, Zatreanu Adrian-Gabriel
Project Page [Summer of Code Project Page]
Status Completed

Project Abstract

@satwikkansal
satwikkansal / Simple Cricket API script
Last active May 27, 2019 13:02
Cheatsheet for Python
#importing the python requests library
import requests
def get_scores():
url = "https://cricscore-api.appspot.com/csa"
#Creatin a GET request
response = requests.get(url)