Skip to content

Instantly share code, notes, and snippets.

@fogus
fogus / 0 - UNIX Fifth Edition
Created July 20, 2011 00:15
UNIX V5, OpenBSD, Plan 9, FreeBSD, and GNU coreutils implementations of echo.c
main(argc, argv)
int argc;
char *argv[];
{
int i;
argc--;
for(i=1; i<=argc; i++)
printf("%s%c", argv[i], i==argc? '\n': ' ');
}
@kylemanna
kylemanna / 7z+tar.md
Last active February 18, 2023 19:18
Archive with tar + 7z + max compression

Overview

7-zip doesn't preserve the Linux/Unix owner/group of files and possibly other details. Use tar instead because it's designed to preserve these things, then just 7zip the tar archive.

Create the archive

tar cf - --exclude=\*.o -v directory | 7z a -si -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on directory.tar.7z
@szepeviktor
szepeviktor / do-fontdetect.js
Created May 19, 2014 17:44
JavaScript/CSS Font Detector by Lalit Patel
// loading on "load" may cause FOUC
window.onload = function() {
var detective = new Detector();
if (!detective.detect('Meat')) {
var url = 'link/to/style.css'
if (document.createStyleSheet) {
try { document.createStyleSheet(url); } catch (e) { }
} else {
var css;
@tomconte
tomconte / snapshot_utility.py
Created July 23, 2014 16:25
Sample Python script to manage Azure Blob Storage snapshots: list snapshots, take a snapshot, delete a snapshot, copy a snapshot to a new Blob.
#!/usr/bin/python
from azure.storage import BlobService
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("container", help="the blob container")
parser.add_argument("blob", help="the blob name")
parser.add_argument("-s", "--snapshot", help="take a new snapshot", action="store_true")
parser.add_argument("-d", "--delete", help="delete a snapshot")
#!/bin/bash
fsWithSnapshots=$(zfs list -Hr -t snapshot tank/share |grep '@' |cut -d '@' -f 1 |uniq)
for fs in $fsWithSnapshots ; do
# Changed to now sort newest to oldest. This will mean that newer snapshots without deltas will get removed.
emptySnapshot=$(zfs list -Hr -d1 -t snapshot -o name,used -S creation $fs |sed '$d' |awk ' $2 == "0B" { print $1 }' )
for snapshot in $emptySnapshot ; do
# Added safety check. Verify the size of the snapshot prior to destroying it
@tsolar
tsolar / laravel-subdirectory.conf
Last active February 27, 2024 03:36
Laravel in subdirectory nginx example
server {
client_body_in_file_only clean;
client_body_buffer_size 32K;
client_max_body_size 300M;
sendfile on;
send_timeout 300s;
# Port that the web server will listen on.
#listen 80;
@fphilipe
fphilipe / exclude.sql
Last active April 25, 2024 23:17
PostgreSQL EXCLUDE constraint
CREATE EXTENSION btree_gist;
CREATE TABLE room_reservations (
room_id integer,
reserved_at timestamptz,
reserved_until timestamptz,
canceled boolean DEFAULT false,
EXCLUDE USING gist (
room_id WITH =, tstzrange(reserved_at, reserved_until) WITH &&
) WHERE (not canceled)
@kshchepanovskyi
kshchepanovskyi / about_message_field_default_value.md
Last active May 22, 2023 14:57
Protobuf: message field and default values

About default value for message fields

If field type is message, what should getter return if it is not set?

Proto2 specification does not define default value for message type, it is defined only for scalar types:

If the default value is not specified for an optional element, a type-specific

Downloading and Syncing Archive.org Collections

Following are instructions on how to use the Internet Archive command-line tool, "ia", to download a collection from Archive.org and keep it synced. The only requirements are that you have Python 2 installed on a Unix-like operating system (i.e. Mac OS X, Linux).

Downloading and Configuring the Ia Command-Line Tool

  1. Download the latest binary of the ia command-line tool:
@Two9A
Two9A / decronym.php
Last active April 9, 2024 23:25
Decronym: A simple Reddit bot
<?php
/**
* Dirty, dirty Reddit bot: Decronym
*/
class Reddit {
const USERNAME = 'Decronym';
const PASSWORD = '***';
const CLIENTID = '***';
const SECRET = '***';