Skip to content

Instantly share code, notes, and snippets.

View themegabyte's full-sized avatar

Shayan themegabyte

View GitHub Profile
@arbales
arbales / handlebars-formatTextForHTML.coffee
Created January 22, 2012 00:08
Replace URLs with links and unicode emoji with images.
LINK_DETECTION_REGEX = /(([a-z]+:\/\/)?(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi
EMOJI_DIRECTORY = "/path/to/assets/emoji/20x20"
# Handlebars is presumed, but you could swap out
ESCAPE_EXPRESSION_FUNCTION = Handlebars.Utils.escapeExpression
MARKSAFE_FUNCTION = (str) -> new Handlebars.SafeString(str)
# Emoji unicode chars become images.
@asabaylus
asabaylus / gist:3071099
Created July 8, 2012 14:12
Github Markdown Heading Anchors

Anchors in Markdown

To create an anchor to a heading in github flavored markdown. Add - characters between each word in the heading and wrap the value in parens (#some-markdown-heading) so your link should look like so:

[create an anchor](#anchors-in-markdown)

@stongo
stongo / app.js
Last active June 13, 2024 11:40
Joi validation in a Mongoose model
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection;
db.on('error', function() {
return console.error.bind(console, 'connection error: ');
});
@sourceperl
sourceperl / th_pinger.py
Last active April 12, 2024 18:56
Python script for do multi-threaded ping
#!/usr/bin/env python
# ping a list of host with threads for increase speed
# use standard linux /bin/ping utility
from threading import Thread
import subprocess
try:
import queue
except ImportError:
import Queue as queue
@schnell18
schnell18 / cgitrc-sample
Created April 10, 2014 14:59
cgitrc sample file with instruction to generate absolute link URL starting with /cgit.cgi/
# Make cgit generate link using absolute URL
virtual-root=/cgit.cgi/
# Enable caching of up to 1000 output entriess
cache-size=1000
# cache time to live
cache-dynamic-ttl=5
cache-repo-ttl=5
@joshnuss
joshnuss / app.js
Last active March 4, 2024 00:01
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./authorization"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@Airdawg5571
Airdawg5571 / ipt
Last active October 18, 2023 07:01
More organized (pretty-printed) iptables output.
#!/bin/bash
# Written and tested on CentOS 7
iptables -nvL |cut -f -9|column -t| sed 's/^Chain/\n&/g'|sed '/^Chain/ s/[ \t]\{1,\}/ /g'|sed '/^[0-9]/ s/[ \t]\{1,\}/ /10g'
@tatsuhiro-t
tatsuhiro-t / author.py
Created March 21, 2016 03:31
List up commit log author from git-log
#!/usr/bin/env python
# script to extract commit author's name from standard input. The
# input should be <AUTHOR>:<EMAIL>, one per line.
# This script expects the input is created by git-log command:
#
# git log --format=%aN:%aE
#
# This script removes duplicates based on email address, breaking a
# tie with longer author name. Among the all author names extract the
# ~/.bashrc: executed by bash(1) for non-login shells.
# .see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If running non interactively, do nothing
########################################################
#|# Preamble #
########################################################
[ -z "$PS1" ] && return
@efrecon
efrecon / run.tpl
Last active May 30, 2024 03:12
`docker inspect` template to regenerate the `docker run` command that created a container
docker run \
--name {{printf "%q" .Name}} \
{{- with .HostConfig}}
{{- if .Privileged}}
--privileged \
{{- end}}
{{- if .AutoRemove}}
--rm \
{{- end}}
{{- if .Runtime}}