Skip to content

Instantly share code, notes, and snippets.

View escuccim's full-sized avatar

Eric A. Scuccimarra escuccim

View GitHub Profile
@vladignatyev
vladignatyev / progress.py
Last active March 31, 2024 22:54
Python command line progress bar in less than 10 lines of code.
# The MIT License (MIT)
# Copyright (c) 2016 Vladimir Ignatev
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#
@smithdanielle
smithdanielle / check.packages.r
Created April 1, 2014 13:23
Check if multiple R packages are installed. Install them if they are not,then load them into the R session.
# check.packages function: install and load multiple R packages.
# Check to see if packages are installed. Install them if they are not, then load them into the R session.
check.packages <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
# Usage example
@andrewjong
andrewjong / pytorch_image_folder_with_file_paths.py
Last active February 27, 2024 09:24
PyTorch Image File Paths With Dataset Dataloader
import torch
from torchvision import datasets
class ImageFolderWithPaths(datasets.ImageFolder):
"""Custom dataset that includes image file paths. Extends
torchvision.datasets.ImageFolder
"""
# override the __getitem__ method. this is the method that dataloader calls
def __getitem__(self, index):
@omoindrot
omoindrot / tensorflow_finetune.py
Last active February 25, 2024 15:00
Example TensorFlow script for fine-tuning a VGG model (uses tf.contrib.data)
"""
Example TensorFlow script for finetuning a VGG model on your own data.
Uses tf.contrib.data module which is in release v1.2
Based on PyTorch example from Justin Johnson
(https://gist.github.com/jcjohnson/6e41e8512c17eae5da50aebef3378a4c)
Required packages: tensorflow (v1.2)
Download the weights trained on ImageNet for VGG:
```
wget http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz
@ninjadq
ninjadq / sample.py
Created March 3, 2016 05:21
django transactions with raw sql and multiple databases
def test_transaction(*args):
create_sql = "INSERT INTO user (name) VALUES (%s)"
transaction.set_autocommit(False, using='uic')
try:
cursor = connections['uic'].cursor()
for u in args:
cursor.execute(create_sql,[u])
except IntegrityError as e:
transaction.rollback(using='uic')
else:
@ramhiser
ramhiser / jaccard.py
Last active November 4, 2021 08:41
Jaccard cluster similarity in Python
import itertools
def jaccard(labels1, labels2):
"""
Computes the Jaccard similarity between two sets of clustering labels.
The value returned is between 0 and 1, inclusively. A value of 1 indicates
perfect agreement between two clustering algorithms, whereas a value of 0
indicates no agreement. For details on the Jaccard index, see:
http://en.wikipedia.org/wiki/Jaccard_index
@juice49
juice49 / UniqueFilename
Created July 2, 2014 10:14
Laravel unique filename
/**
* Creates a unique filename by appending a number
*
* i.e. if image.jpg already exists, returns
* image2.jpg
*/
function uniqueFilename($path, $name, $ext) {
$output = $name;
$basename = basename($name, '.' . $ext);
@alceufc
alceufc / softmax.py
Created January 24, 2016 19:45
Compute Softmax function using numpy.
import numpy as np
def softmax(x):
"""
Compute softmax values for each sets of scores in x.
Rows are scores for each class.
Columns are predictions (samples).
"""
scoreMatExp = np.exp(np.asarray(x))