Skip to content

Instantly share code, notes, and snippets.

View julien-c's full-sized avatar
Real artists ship

Julien Chaumond julien-c

Real artists ship
View GitHub Profile
@Narsil
Narsil / pure_torch.py
Created November 10, 2022 15:06
Loading a safetensors file with pure torch only
import mmap
import torch
import json
import os
from huggingface_hub import hf_hub_download
def load_file(filename, device):
with open(filename, mode="r", encoding="utf8") as file_obj:
with mmap.mmap(file_obj.fileno(), length=0, access=mmap.ACCESS_READ) as m:
@smnbbrv
smnbbrv / promisified-grpc-client.ts
Last active November 4, 2023 21:22
Promisify @grpc-js service client with typescript
import { Client, ServiceError, Metadata, CallOptions, ClientUnaryCall } from '@grpc/grpc-js';
import { Message } from 'google-protobuf';
type OriginalCall<T, U> = (request: T, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError, res: U) => void) => ClientUnaryCall;
type PromisifiedCall<T, U> = ((request: T, metadata?: Metadata, options?: Partial<CallOptions>) => Promise<U>);
export type Promisified<C> = { $: C; } & {
[prop in Exclude<keyof C, keyof Client>]: (C[prop] extends OriginalCall<infer T, infer U> ? PromisifiedCall<T, U> : never);
}
@hervenivon
hervenivon / boto3_multipartupload.py
Created November 18, 2020 21:31
Upload large files in multi part
import boto3
import os
import sys
import threading
from boto3.s3.transfer import TransferConfig
s3_client = boto3.client('s3')
# S3 transfer documentation: https://boto3.amazonaws.com/v1/documentation/api/1.9.156/reference/customizations/s3.html?highlight=transferconfig#boto3.s3.transfer.TransferConfig
@julien-c
julien-c / ModelInfo.ts
Last active October 15, 2020 20:46
Model tag <=> pipeline type logic, for public reference
export class ModelInfo {
/**
* Key to config.json file.
*/
key: string;
etag: string;
lastModified: Date;
size: number;
modelId: ModelId;
author?: AuthorId;
@sshleifer
sshleifer / PreTweet Checklist
Created May 15, 2020 16:02
Before you tweet checklist
- for mention in tweet.grep('@'): assert twitter.get(mention) == expected_person
- assert photo has tags
- if thread: numbers make sense or down emoji
- all links work
- read it over once more
@aditya-malte
aditya-malte / smallberta_pretraining.ipynb
Created February 22, 2020 13:41
smallBERTa_Pretraining.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@natecook1000
natecook1000 / NSTimer+Closure.swift
Last active January 6, 2024 07:23
Scheduled NSTimer with a Swift closure
extension NSTimer {
/**
Creates and schedules a one-time `NSTimer` instance.
- Parameters:
- delay: The delay before execution.
- handler: A closure to execute after `delay`.
- Returns: The newly-created `NSTimer` instance.
*/
@cromandini
cromandini / universal-framework.sh
Last active February 12, 2024 12:13 — forked from cconway25/gist:7ff167c6f98da33c5352
This run script will build the iphoneos and iphonesimulator schemes and then combine them into a single framework using the lipo tool (including all the Swift module architectures).
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
@arthurdarcet
arthurdarcet / gist:6728522
Created September 27, 2013 13:23
Variadic function in Objective-C
- (void)fun:(NSString *)first, ...
{
va_list args;
va_start(args, first);
for (NSString* arg = first; arg != nil; arg = va_arg(args, NSString*))
NSLog(@"var: %@", arg);
va_end(args);
}
@veritech
veritech / social.m
Created September 19, 2012 20:37
How to use iOS 6's social framework
/*
* This code uses the Social.framework & the AFNetworking library
*/
ACAccountStore *store;
ACAccountType *accountType;
//Create an ACAccountStore instance
store = [[ACAccountStore alloc] init];