Skip to content

Instantly share code, notes, and snippets.

Avatar

Ehsan Kia EhsanKia

View GitHub Profile
@EhsanKia
EhsanKia / peer.d.ts
Last active Aug 29, 2015
peerjs.d.ts
View peer.d.ts
interface DataConnection {
send(data: any): void;
close(): void;
on(event: string, callback: (p?: any) => void): void;
bufferSize: number;
dataChannel: Object;
label: string;
metadata: any;
open: boolean;
peerConnection: Object;
@EhsanKia
EhsanKia / minverva_transcript
Created Apr 25, 2014
Fetches transcript from minerva
View minverva_transcript
import requests
LOGIN_URL = "https://horizon.mcgill.ca/pban1/twbkwbis.P_ValLogin"
DATA_URL = "https://horizon.mcgill.ca/pban1/bzsktran.P_Display_Form"
def login(username, password):
info = {"sid": username, "PIN": password}
cookies = {"TESTID": "set"}
r = requests.post(LOGIN_URL, data=info, cookies=cookies)
return r.cookies.get("SESSID")
View turn2kill.py
from random import shuffle
def trial():
# Deck comprised of 30 cards, two of each. Assume:
# 0=Lightwarden, 1=CoH, 2=Pyromancer, 3=Silence
deck = range(15) + range(15)
shuffle(deck)
# Initial 4 draws
hand = [deck.pop() for i in range(4)]
View gist:259f3f97a0e371f59617
### Keybase proof
I hereby claim:
* I am ehsankia on github.
* I am ehsankia (https://keybase.io/ehsankia) on keybase.
* I have a public key whose fingerprint is 00CB 342D 7DE5 B7A7 052E 6FDF 6174 9B8C 5D4F A042
To claim this, I am signing this object:
@EhsanKia
EhsanKia / better_rabbit.js
Last active Feb 12, 2017
Rabb.it Twitch emotes
View better_rabbit.js
var twitchEmotes = {};
var bttvEmotes = {};
$.getJSON('https://twitchemotes.com/api_cache/v2/global.json', function(data) {
$.each(data.emotes, function(key, val) {
twitchEmotes[key] = val.image_id;
});
})
$.getJSON('https://twitchemotes.com/api_cache/v2/subscriber.json', function(data) {
@EhsanKia
EhsanKia / commerical_obs.html
Created Feb 14, 2017
Plays commercials and music in CLR browser
View commerical_obs.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Commercials</title>
<style type="text/css">
#commercial {
width: 100%;
height: 100%;
opacity: 0;
@EhsanKia
EhsanKia / pi.py
Created Mar 14, 2017
Generate Pi from checking if two random numbers are coprime. https://www.youtube.com/watch?v=RZBhSi_PwHU
View pi.py
from math import sqrt
from random import randint
try:
from math import gcd
except:
from fractions import gcd
ITERATIONS = 1000000
MAX_INT = 1000000000
@EhsanKia
EhsanKia / keybase.md
Created Jan 7, 2018
Keybase verification
View keybase.md

Keybase proof

I hereby claim:

  • I am ehsankia on github.
  • I am ehsankia (https://keybase.io/ehsankia) on keybase.
  • I have a public key whose fingerprint is 4FCC DA95 C5D0 DF8F 5A10 619A 5D50 ED63 7B07 456F

To claim this, I am signing this object:

@EhsanKia
EhsanKia / launchy.ini
Created Sep 27, 2016
Keypirinha Plugin to replicate Launchy's database format
View launchy.ini
#
# Launchy Package configuration file
#
[main]
# Plugin's main configuration section.
# (Nothing here for now)
[directories]
@EhsanKia
EhsanKia / resize_image.py
Last active Oct 13, 2018
Simple function to smartly resize an image with PIL.
View resize_image.py
# There are four ways a resize can go:
# 1. You only specify a width -> image is resized to have that width while conserving aspect ratio
# 2. You only specify a height -> image is resized to have that height while conserving aspect ratio
# 3. You specify width and height with crop off -> Image is resized to fit inside the dimensions while conserving aspect ratio
# 4. You specify width and height with crop on -> Image is cropped and resized to the new dimensions, centered.
#
# NOTE: This function can potentially scale up your image.
# You can avoid that if that's important for your use case by checking
# width and height against old values before resizing at the end.