Skip to content

Instantly share code, notes, and snippets.

View allenanie's full-sized avatar
🏔️
Gradient ascending

Allen Nie allenanie

🏔️
Gradient ascending
View GitHub Profile
@allenanie
allenanie / Singleton
Last active August 29, 2015 13:56
PHP Singleton for AWS SDK S3
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once 'vendor/autoload.php';
use Aws\S3\S3Client;
final class AWS_S3
{
private static $client = null;
@allenanie
allenanie / pythonEncodeDetect.py
Created April 19, 2014 16:49
Python File Encoding Detect with CLI Tool
import cmd
import string, sys
from chardet.universaldetector import UniversalDetector
class CLI(cmd.Cmd):
def __init__(self):
cmd.Cmd.__init__(self)
self.prompt = '$'
self.path = ''
self.intro = '''Encoding Detection Usage Guide:
@allenanie
allenanie / EasyToCalculateCourseraVideoLength
Last active October 9, 2015 23:42
Easy To Calculate Coursera Video Length
//For "# min" type
var searchCorpus = $('a.lecture-link').text();
var matches = searchCorpus.match(/(\d).+min/gm);
var bigResult = [];
for (index in matches) {bigResult.push(matches[index].match(/([\d]+)/g)[0]);}
var sum = 0;
for (index in bigResult) {sum = sum + parseInt(bigResult[index]);}
/*=============================================
= User Guide
@allenanie
allenanie / gist:a45d4ac490053ad1a9cf
Created September 26, 2015 22:59 — forked from jeamland/gist:11284662
Bluetooth LE on OS X via Python
import select
import socket
import sys
import objc
from PyObjCTools import AppHelper
objc.loadBundle("CoreBluetooth", globals(),
bundle_path=objc.pathForFramework(u'/System/Library/Frameworks/IOBluetooth.framework/Versions/A/Frameworks/CoreBluetooth.framework'))
@allenanie
allenanie / MontyHall.py
Created October 9, 2015 23:41
This python program simulates the simplest Monty Hall 3-door problem. No optimization, but can be easily extended to count for many-door situations.
# Monty Hall simulation
import numpy as np
winningdoor = -1 # ordinal numbers
firstChoice = -1 # both first pick and final pick
closedDoor = -1
finalChoice = -1
@allenanie
allenanie / CoinToss.py
Created October 16, 2015 22:48
Simulate a coin toss (for Stanford EE178)
# simulate coin toss
import numpy as np
X = np.zeros(3) # random variable X: X[0], X[1], X[2]
X_0_sets = set()
X_1_sets = set()
X_2_sets = set()
@allenanie
allenanie / CouponCollectors.py
Created October 30, 2015 20:13
A Python simulation to Coupon Collector's Problem
# simulate coupon collector's problem
import numpy as np
def run(n):
"""
n: number of different coupons (stamps)
return: days it took to achieve such goal
"""
@allenanie
allenanie / brnn.py
Last active April 22, 2023 17:44
Bayesian Recurrent Neural Network Implementation
"""
An implementation of the `Local reparameterization trick`
from Kingma & Wellings and
Bayesian RNN
from Fortunato, Blundell & Vinyals
"""
import os
import time
import copy
from os.path import join as pjoin
# -*- coding: utf-8 -*-
import spacy
import logging
import string
import os
log_fmt = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
logging.basicConfig(level=logging.INFO, format=log_fmt)
logger = logging.getLogger(__name__)
Download Google Drive files with WGET
Example Google Drive download link:
https://docs.google.com/open?id=[ID]
To download the file with WGET you need to use this link:
https://googledrive.com/host/[ID]
Example WGET command: