Skip to content

Instantly share code, notes, and snippets.

@darcwader
darcwader / resize-ci.swift
Created August 31, 2016 08:43
Resizing Image using Core Image
extension UIImage {
func resizeCI(size:CGSize) -> UIImage? {
let scale = (Double)(size.width) / (Double)(self.size.width)
let image = UIKit.CIImage(CGImage:self.CGImage!)
let filter = CIFilter(name: "CILanczosScaleTransform")!
filter.setValue(image, forKey: kCIInputImageKey)
filter.setValue(NSNumber(double:scale), forKey: kCIInputScaleKey)
filter.setValue(1.0, forKey:kCIInputAspectRatioKey)
let outputImage = filter.valueForKey(kCIOutputImageKey) as! UIKit.CIImage
@darcwader
darcwader / imageFromSampleBuffer
Created December 9, 2015 06:36
Convert SampleBuffer to UIImage in AVCaptureVideoDataOutputSampleBufferDelegate in Swift
func imageFromSampleBuffer(sampleBuffer:CMSampleBufferRef) -> UIImage? {
if let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) {
CVPixelBufferLockBaseAddress(imageBuffer,0)
let baseAddress = CVPixelBufferGetBaseAddress(imageBuffer)
let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer)
let width = CVPixelBufferGetWidth(imageBuffer)
let height = CVPixelBufferGetHeight(imageBuffer)
let colorSpace = CGColorSpaceCreateDeviceRGB()
let context = CGBitmapContextCreate(baseAddress,width,height,8,bytesPerRow, colorSpace, CGBitmapInfo.ByteOrder32Little.rawValue | CGImageAlphaInfo.PremultipliedFirst.rawValue)
@darcwader
darcwader / gist:d73e2f7ad407225e5d9e8d0f27b7b97f
Created February 24, 2022 16:32
figma install in linux
cd /
find . -name figma-linux_figma-linux.desktop 2>/dev/null
less ./var/lib/snapd/desktop/applications/figma-linux_figma-linux.desktop
cat ./var/lib/snapd/desktop/applications/figma-linux_figma-linux.desktop
ls -l ./var/lib/snapd/desktop/applications/figma-linux_figma-linux.desktop
sudo cp ./var/lib/snapd/desktop/applications/figma-linux_figma-linux.desktop ~/.local/share/applications
vim ~/.local/share/applications/mimeapps.list
xdg-mime default figma-linux_figma-linux.desktop x-scheme-handler/figma
xdg-mime query default x-scheme-hander/figma
cat /usr/share/applications/figma-linux.desktop || cat /var/lib/snapd/desktop/applications/figma-linux_figma-linux.desktop\n
@darcwader
darcwader / Makefile
Created November 25, 2021 18:38
migration job makefile
K:=kubectl
NS:=default
.PHONY: migrate
migrate:
$(K) apply -f migration/migration-job.yaml -n $(NS)
$(K) wait --for=condition=complete --timeout=300s jobs/mlserver-migration -n $(NS)
$(K) get job mlserver-migration -o "jsonpath={.metadata.labels.controller-uid}" -n $(NS) \
| xargs -I {} $(K) get po -l controller-uid={} -o "jsonpath={.items[0].metadata.name}" -n $(NS) \
| xargs -I {} $(K) logs {} -n $(NS) -c mlserver-django \
@darcwader
darcwader / migration-job.yaml
Created November 25, 2021 18:32
django migration job
apiVersion: batch/v1
kind: Job
metadata:
name: mlserver-migration
spec:
parallelism: 1
template:
spec:
containers:
- name: cloudsql-proxy
@darcwader
darcwader / api.py
Created November 25, 2021 18:18
swagger documentation for django viewset
class PlanViewset(viewsets.ModelViewSet):
class Schema(AutoSchema):
def get_operation(self, path, method):
op = super().get_operation(path, method)
if method == "GET" and path.split('/')[-2] != '{id}':
op['parameters'].append({
"name": "time_window_id",
"in": "query",
@darcwader
darcwader / countryinfo.py
Created September 29, 2021 04:15 — forked from pamelafox/countryinfo.py
Python list of country codes, names, continents, capitals, and pytz timezones
countries = [
{'timezones': ['Europe/Andorra'], 'code': 'AD', 'continent': 'Europe', 'name': 'Andorra', 'capital': 'Andorra la Vella'},
{'timezones': ['Asia/Kabul'], 'code': 'AF', 'continent': 'Asia', 'name': 'Afghanistan', 'capital': 'Kabul'},
{'timezones': ['America/Antigua'], 'code': 'AG', 'continent': 'North America', 'name': 'Antigua and Barbuda', 'capital': "St. John's"},
{'timezones': ['Europe/Tirane'], 'code': 'AL', 'continent': 'Europe', 'name': 'Albania', 'capital': 'Tirana'},
{'timezones': ['Asia/Yerevan'], 'code': 'AM', 'continent': 'Asia', 'name': 'Armenia', 'capital': 'Yerevan'},
{'timezones': ['Africa/Luanda'], 'code': 'AO', 'continent': 'Africa', 'name': 'Angola', 'capital': 'Luanda'},
{'timezones': ['America/Argentina/Buenos_Aires', 'America/Argentina/Cordoba', 'America/Argentina/Jujuy', 'America/Argentina/Tucuman', 'America/Argentina/Catamarca', 'America/Argentina/La_Rioja', 'America/Argentina/San_Juan', 'America/Argentina/Mendoza', 'America/Argentina/Rio_Gallegos', 'America/Argentina/Ushuai
FROM python:3.8-buster
RUN apt-get update && apt-get install -y --no-install-recommends openssh-server
RUN mkdir -p /run/sshd && mkdir -p /var/run/sshd && mkdir -p /root/.ssh
ARG PWD
RUN ssh-keygen -A
RUN echo "root:$PWD" | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
EXPOSE 22
@darcwader
darcwader / resize-vi.swift
Created August 31, 2016 08:46
Resize Image using vImage
extension UIImage {
func resizeVI(size:CGSize) -> UIImage? {
let cgImage = self.CGImage!
var format = vImage_CGImageFormat(bitsPerComponent: 8, bitsPerPixel: 32, colorSpace: nil,
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.First.rawValue),
version: 0, decode: nil, renderingIntent: CGColorRenderingIntent.RenderingIntentDefault)
var sourceBuffer = vImage_Buffer()
defer {
sourceBuffer.data.dealloc(Int(sourceBuffer.height) * Int(sourceBuffer.height) * 4)
@darcwader
darcwader / conda-env-setup.sh
Created July 21, 2019 02:31
Basic setup of jupyter notebook environment with python3.6 , opencv, matplotlib
export NAME=gurkha
conda create -n gurkha python=3.6
conda activate gurkha
conda install opencv
pip install moviepy
pip install matplotlib
pip install jupyter
pip install jupyter_contrib_nbextensions
pip install nbextension install
jupyter contrib nbextension install