Skip to content

Instantly share code, notes, and snippets.

@anand2312
anand2312 / pymongo-to-motor.md
Last active May 8, 2024 08:47
pymongo vs Motor

pymongo vs Motor

Motor is an async Python driver for MongoDB.

When should I use Motor?

You should use Motor when you're trying to interact with a MongoDB database in an asynchronous context. When you're making something that needs to be asynchronous (like a web server, or most commonly from what I've seen here, Discord bots), you also want all the database calls to be done asynchronously. But pymongo is synchronous, i.e it is blocking, and will block the execution of your asynchronous program for the time that it is talking to the database.

Okay, How do I switch now?!

Thankfully for us, switching from pymongo to Motor isn't too hard, and won't need you to change much code. This process can be roughly summarized as:

Step 1: Install Motor, and import it

Installing can be done with pip - pip install motor

@gkbrk
gkbrk / lolcat.asm
Created July 27, 2016 13:26
Lolcat clone in x64 assembly
section .data
char_buffer db 0
section .text
global _start
_start:
mov r12, 0
.loop:
call read_char
@JamesDunne
JamesDunne / fsw.c
Created February 20, 2017 16:35
C library for polling 16 active-low button states via SX1509 over I2C bus from Raspberry Pi Model B
typedef unsigned char u8;
typedef u8 byte;
#include "sx1509_registers.h"
// https://learn.sparkfun.com/tutorials/sx1509-io-expander-breakout-hookup-guide#sx1509-breakout-board-overview
// SX1509 breakout board exposes ADD1 and ADD0 jumpers for configuring I2C address.
// ADD1 = 0, ADD0 = 0
#define i2c_sx1509_btn_addr 0x3E
@Geal
Geal / future.c
Last active May 8, 2024 08:44
small future and promise library in C with pthreads
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <stdbool.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include "future.h"
@phanan
phanan / runner.js
Last active May 8, 2024 08:44
Record a webpage with PhantomJS and FFMpeg
// Run this from the commandline:
// phantomjs runner.js | ffmpeg -y -c:v png -f image2pipe -r 24 -t 10 -i - -c:v libx264 -pix_fmt yuv420p -movflags +faststart output.mp4
var page = require('webpage').create(),
address = 'http://s.codepen.io/phanan/fullembedgrid/YPLewm?type=embed&safe=true&_t=1424767252279',
duration = 3, // duration of the video, in seconds
framerate = 24, // number of frames per second. 24 is a good value.
counter = 0,
width = 500,
height = 500;
@abraithwaite
abraithwaite / chill-zoom.sh
Last active May 8, 2024 08:43
Zoom in Systemd Cgroups on Linux. Change the max allocations to fit your workstation.
#!/usr/bin/bash -xe
cat <<EOF > "${HOME}/.config/systemd/user/zoom.slice"
[Slice]
AllowedCPUs=0-4
MemoryHigh=6G
EOF
cat /usr/share/applications/Zoom.desktop | sed -E 's#^(Exec=).*$#Exec=/usr/bin/systemd-run --user --slice=zoom.slice /opt/zoom/ZoomLauncher#' > "${HOME}/.local/share/applications/Zoom.desktop"
@zachrank
zachrank / wsl2-zsh-powerlevel10k.md
Created August 8, 2022 01:43
WSL 2 + Windows Terminal + Oh My Zsh + Powerlevel10k

WSL 2 + Windows Terminal + Oh My Zsh + Powerlevel10k

wsl2-zsh-powerlevel10k

This gist takes heavy inspiration from kevin-smets / iterm2-solarized.md gist for iTerm2.

Windows Subsystem for Linux 2 (WSL 2)

The first thing that you will want to do is install WSL 2 and a Linux distro.

#!/usr/bin/env bash
# --slave /usr/bin/$1 $1 /usr/bin/$1-\${version} \\
function register_clang_version {
local version=$1
local priority=$2
update-alternatives \
--install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${version} ${priority} \
@jornane
jornane / GROW.md
Created October 23, 2017 12:12
How to grow a partition in Linux

How to grow a partition in Linux

This guide will walk you through the steps required to grow a partition in Linux. You will have to reboot through this guide.

  1. If possible, make a snapshot.

Often, you will want to grow the partition table because you made your virtual hard disk too small, and you tried to extend it in your hypervisor, only to find out that your partition is still the same size as it was before.