Skip to content

Instantly share code, notes, and snippets.

View pascalc's full-sized avatar

Pascal Chatterjee pascalc

View GitHub Profile
FROM ubuntu:latest
RUN apt-get update
RUN echo "Hello Dockerfile"
@pascalc
pascalc / port-forwarding.md
Created November 12, 2017 13:34
SSH Remote Port Forwarding
ssh -nNT -R <remote-port>:localhost:<local-port> -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" user@example.com

This will forward local-port (from localhost) to remote-port on example.com, and set options to keep the connection alive

# Schema: src/db/schema.py
class Perspective(Base, MyMixin):
__tablename__ = 'perspective'
id = Column(Integer, primary_key=True)
gender = Column(String(6), nullable=False)
text = Column(Text, nullable=False)
social_text = Column(Text, nullable=True)
created_at = Column(DateTime, default=datetime.now)
submissions = orm.relationship('Submission', backref='perspective',
lazy='dynamic')
@pascalc
pascalc / gist:7876720
Created December 9, 2013 17:51
knock-knock
(clear!)
(defparser
["Knock ?knock"])
(defresponse
(and* (known ["?knock"]) (unknown ["?whosthere"]))
(fn [?knock]
(remember! {"?whosthere" true})
"Who's there?"))
@pascalc
pascalc / Moths
Last active December 28, 2015 12:19
Moths
(clear!)
;; Background
(rectangle
(width "100%")
(height "100%")
(fill "#383032")
(stroke-width 0))
(defn draw-moth
(clear!)
(def colors
["White"
"Silver"
"Gray"
"Black"
"Red"
"Maroon"
"Yellow"
@pascalc
pascalc / Google App Engine APNS
Created August 20, 2013 21:21
iOS push messages from Google App Engine, using PyAPNS (https://github.com/djacobs/PyAPNs)
from apns import APNs, Payload
APNS_CLIENT = APNs(cert_file="cert.pem")
def push_to_ios_batch(message, devices, user_id):
payload = Payload(alert=message, badge=1)
for device_push_id in [d['device_push_id'] for d in devices]:
push_succeeded = False
while not push_succeeded:
try:
@pascalc
pascalc / Declarative Clojure
Created November 3, 2012 16:21
Imperative vs declarative prime numbers
(defn factor-of?
[n d]
(= (mod n d) 0))
(defn possible-factors-of
[n]
(range 2 n))
(defn prime? [n]
(cond
@pascalc
pascalc / gist:3859270
Created October 9, 2012 14:44
Java Pollard's Rho
import java.math.BigInteger;
import java.security.SecureRandom;
public class PollardOptimised {
private final static BigInteger ZERO = new BigInteger("0");
private final static BigInteger ONE = new BigInteger("1");
private final static BigInteger TWO = new BigInteger("2");
private final static SecureRandom random = new SecureRandom();
public static BigInteger f(BigInteger x, BigInteger c, BigInteger N) {
@pascalc
pascalc / gist:3805249
Created September 29, 2012 21:41
Monty Hall
(defn delete [items l]
(remove (set items) l))
(defn monty-hall
[switch?]
(let [doors (range 3)
car (rand-nth doors)
guess-1 (rand-nth doors)
hint (rand-nth
(delete [guess-1 car] doors))