Skip to content

Instantly share code, notes, and snippets.

View mrsarm's full-sized avatar
🏠
Working from home

Mariano Ruiz mrsarm

🏠
Working from home
View GitHub Profile
@solace
solace / migration.py
Created November 6, 2020 14:00
Django: Add Permissions to Groups during Migration
# YMMV
from django.conf import settings
from django.contrib.auth.models import Group, Permission
from django.core.management.sql import emit_post_migrate_signal
from django.db import migrations, models
import django.db.models.deletion
import logging
@anthonyjoeseph
anthonyjoeseph / GenerateClient.ts
Last active July 4, 2024 01:00
Typescript React + Express SSR
import serialize from 'serialize-javascript';
import path from 'path';
import fs from 'fs';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
export default <P>(
App: React.ReactElement<P>,
globalState: string | undefined,
): Promise<string> => new Promise((resolve, reject) => {
@mrsarm
mrsarm / find-text
Last active June 19, 2023 16:46
find-text: Bash script to find text or regex in a given path with context display, and omitting temp folders
#!/usr/bin/env bash
#
# find-text: Find text or regex in a given path with context display,
# and omitting temp folders.
#
if [ "$1" == "-h" -o "$1" == "--help" ]
then
cat >&2 <<-'EOF'
find-text: find text or regex in a given path with context display,
@stav
stav / ScrapyLog.sublime-syntax
Created January 10, 2019 23:17
Sublime Text Syntax Definition for Scrapy log files
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
# See http://www.sublimetext.com/docs/3/scope_naming.html
#
# Note that blackslashes don't need to be escaped within single quoted strings
# in YAML. When using single quoted strings, only single quotes need to be
# escaped: this is done by using two single quotes next to each other.
#
# Scope discovery - Ctrl Shft Alt p
@mrsarm
mrsarm / applogs.sh
Last active January 17, 2019 20:44
applogs.sh: Show logs from AWS Cloud Watch Logs from a given group/stream in a human readable way (see requirements below)
#!/usr/bin/env bash
#
# applogs.sh
#
# Show logs from AWS Cloud Watch Logs from a given group/stream
# in a human readable way.
#
# Requires awscli and jq 1.5+, and if you are using Mac OS also
# needs coreutils installed.
#
@PurpleBooth
PurpleBooth / README-Template.md
Last active November 13, 2024 22:21
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@justmoon
justmoon / custom-error.js
Last active June 26, 2024 09:36 — forked from subfuzion/error.md
Creating custom Error classes in Node.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
@nolanlawson
nolanlawson / couchdb_changes.md
Last active December 21, 2023 03:22
Anatomy of the CouchDB changes feed

Anatomy of the CouchDB changes feed

I just spent a lot of time finally understanding CouchDB's changes feed, so I thought I'd do a short writeup here.

The mystery

Let's imagine the following changes to the database. There are two documents, A and B:

_id seq rev winner?
@fogleman
fogleman / distinct.py
Last active December 1, 2020 05:07
Python Unique / Distinct Elements Iterator
def distinct(iterable, keyfunc=None):
seen = set()
for item in iterable:
key = item if keyfunc is None else keyfunc(item)
if key not in seen:
seen.add(key)
yield item
if __name__ == '__main__':
x = [0, 0, 1, 0, 1, 2, 2, 1, 0]
@BYVoid
BYVoid / gist:7749193
Created December 2, 2013 13:10
Simple FTP server using pyftpdlib
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
authorizer = DummyAuthorizer()
authorizer.add_user("byvoid", "pass", "/home/byvoid/ftp", perm="elradfmw")
handler = FTPHandler
handler.authorizer = authorizer