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
###########################################
# serialization of indexes to byte arrays
###########################################
def serialize_index(index):
""" convert an index to a numpy uint8 array """
writer = faiss.VectorIOWriter()
faiss.write_index(index, writer)
return faiss.vector_to_array(writer.data)
@MikulasZelinka
MikulasZelinka / pytorch_pad_pack_minimal.py
Last active May 30, 2024 01:47
pytorch: handling sentences of arbitrary length (dataset, data_loader, padding, embedding, packing, lstm, unpacking)
"""
sort-of minimal end-to-end example of handling input sequences (sentences) of variable length in pytorch
the sequences are considered to be sentences of words, meaning we then want to use embeddings and an RNN
using pytorch stuff for basically everything in the pipeline of:
dataset -> data_loader -> padding -> embedding -> packing -> lstm -> unpacking (~padding)
based mostly on: https://github.com/HarshTrivedi/packing-unpacking-pytorch-minimal-tutorial
pytorch version 1.4.0
gist url: https://gist.github.com/MikulasZelinka/9fce4ed47ae74fca454e88a39f8d911a
"""
@iamtekeste
iamtekeste / Download Google Drive files with WGET
Created July 8, 2015 11:00
Download Google Drive files with WGET
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:
@lmars
lmars / flynn-mongodb.txt
Created March 14, 2015 16:37
Flynn MongoDB
# create a mongo app
flynn create --remote "" mongo
# create a release using the latest (at the time of writing) Docker MongoDB image
flynn -a mongo release add -f config.json "https://registry.hub.docker.com?name=mongo&id=216d9a0e82646f77b31b78eeb0e26db5500930bbd6085d5d5c3844ec27c0ca50"
# scale the server to one process. This may time out initially as the server pulls the image, but watch "flynn -a mongo ps" and it should come up.
flynn -a mongo scale server=1
# mongo should now be running in the cluster at mongo.discoverd:27017
@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
@alexlib
alexlib / split_image_4_quarters.py
Last active May 16, 2021 14:04
Python code using PIL to split the image into 4 quarters. useful for the four-view image splitter 3D-PTV project on http://www.openptv.net
from PIL import Image
import os
import glob
import numpy as np
def crop(im, height, width):
# im = Image.open(infile)
imgwidth, imgheight = im.size
rows = np.int(imgheight/height)
@jeamland
jeamland / gist:11284662
Created April 25, 2014 10:20
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 / 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;
@visenger
visenger / install_scala_sbt.sh
Last active January 31, 2023 19:10
Scala and sbt installation on ubuntu 12.04
#!/bin/sh
# one way (older scala version will be installed)
# sudo apt-get install scala
#2nd way
sudo apt-get remove scala-library scala
wget http://www.scala-lang.org/files/archive/scala-2.11.4.deb
sudo dpkg -i scala-2.11.4.deb
sudo apt-get update
@dariocravero
dariocravero / README.md
Created October 20, 2012 05:25
Save files in Meteor

Create a Meteor app and put the client_/server_ files in a client/server directories. Also, create a public dir to save the uploaded files.