Skip to content

Instantly share code, notes, and snippets.

View vsajip's full-sized avatar

Vinay Sajip vsajip

View GitHub Profile
@vsajip
vsajip / deepcopy.lua
Created February 5, 2022 09:12 — forked from Deco/deepcopy.lua
Lua Non-recursive Deep-copy
--[[ deepcopy.lua
Deep-copy function for Lua - v0.2
==============================
- Does not overflow the stack.
- Maintains cyclic-references
- Copies metatables
- Maintains common upvalues between copied functions (for Lua 5.2 only)
TODO
@vsajip
vsajip / email_header_parser.rb
Created January 5, 2022 05:10 — forked from pmarreck/email_header_parser.rb
Superfast email header parser in Ruby, using regular expressions. This solution is 250 times faster than using the "Mail" gem. :O Time with my regex: 0.063965 seconds Time with Mail gem: 16.327161 seconds Note that I included some encoding-fix code. YMMV and encoding fixes are all debatable or fail in some corner case.
require 'ap'
require 'mail'
# String monkeypatch
# This is one of many possible "encoding problem" solutions. It's actually an intractable problem
# but you'd have to read "Gödel, Escher, Bach" to understand why...
class String
def clean_utf8
# self.force_encoding("UTF-8").encode("UTF-16BE", :invalid=>:replace, :replace=>"?").encode("UTF-8")
unpack('C*').pack('U*') if !valid_encoding?
@vsajip
vsajip / pr.md
Created December 24, 2021 13:59 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@vsajip
vsajip / gist:b5d678fe128c566d4827ed04632eceb3
Last active December 1, 2021 19:08 — forked from dusual/gist:9838932
Heroku Bottle app
mkdir heroku
cd heroku/
virtualenv --no-site-packages env
source env/bin/activate
pip install bottle gevent
pip freeze > requirements.txt
cat >app.py <<EOF
try:
import gevent.monkey
@vsajip
vsajip / remove_silence.py
Created April 9, 2021 17:18 — forked from fred9/remove_silence.py
Remove silences
# From https://stackoverflow.com/questions/29547218/
# remove-silence-at-the-beginning-and-at-the-end-of-wave-files-with-pydub
from pydub import AudioSegment
def detect_leading_silence(sound, silence_threshold=-50.0, chunk_size=10):
'''
sound is a pydub.AudioSegment
silence_threshold in dB
chunk_size in ms
@vsajip
vsajip / htpasswd.py
Created October 28, 2020 12:42 — forked from eculver/htpasswd.py
htpasswd script in python (no need to install apache utils)
#!/usr/local/bin/python
"""Replacement for htpasswd"""
# Original author: Eli Carter
import os
import sys
import random
from optparse import OptionParser
# We need a crypt module, but Windows doesn't have one by default. Try to find
@vsajip
vsajip / home-server.md
Created October 26, 2020 12:21 — forked from nileshtrivedi/home-server.md
Home Server setup: Raspberry PI on Internet via reverse SSH tunnel

Raspberry Pi on Internet via reverse SSH tunnel

HackerNews discussed this with many alternative solutions: https://news.ycombinator.com/item?id=24893615

I already have my own domain name: mydomain.com. I wanted to be able to run some webapps on my Raspberry Pi 4B running perpetually at home in headless mode (just needs 5W power and wireless internet). I wanted to be able to access these apps from public Internet. Dynamic DNS wasn't an option because my ISP blocks all incoming traffic. ngrok would work but the free plan is too restrictive.

I bought a cheap 2GB RAM, 20GB disk VM + a 25GB volume on Hetzner for about 4 EUR/month. Hetzner gave me a static IP for it. I haven't purchased a floating IP yet.

@vsajip
vsajip / InlineInlineMonacoEditor.stories.tsx
Created August 17, 2020 10:33 — forked from abersnaze/InlineInlineMonacoEditor.stories.tsx
React component, in typescript, wrapping Monaco editor to automatically grow & shrink with content to avoid scroll.
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import InlineMonacoEditor from './InlineMonacoEditor';
export const LINES = [
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'Aenean aliquet, nulla eget auctor porttitor, lacus urna',
'posuere purus, at suscipit orci sapien quis est. Curabitur',
@vsajip
vsajip / typescript-web-components.md
Created April 25, 2020 18:21 — forked from aelbore/typescript-web-components.md
Step by Step creating web components in typescript using rollup

Getting Started

  • Install Dependencies
    npm init
    npm install --save-dev ts-node typescript tslib express @types/express
    

Create your web server

  • Create server.ts in root folder of your app.
@vsajip
vsajip / overlay_pdf.py
Created April 11, 2020 15:19 — forked from dwayneblew/overlay_pdf.py
Overlay text on a PDF template using fpdf and PyPDF2
import fpdf
from PyPDF2 import PdfFileWriter, PdfFileReader
overlay_pdf_file_name = 'overlay_PDF.pdf'
pdf_template_file_name = 'base_PDF_template.pdf'
result_pdf_file_name = 'final_PDF.pdf'
# This section creates a PDF containing the information you want to enter in the fields
# on your base PDF.