Skip to content

Instantly share code, notes, and snippets.

View larrynung's full-sized avatar

larrynung larrynung

View GitHub Profile
@SoEasy
SoEasy / tscontract.ts
Created December 12, 2017 13:10
TypeScript contract-based decorators
type MethodDecorator = (target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) =>
TypedPropertyDescriptor | void;
type AssertFn = (...args: Array<any>) => void;
class TSContract {
private static isCustomContractInterruptionCb: boolean = false;
private static contractInterruptionCb(message: string): void {
console.warn(message);
@rluisr
rluisr / schemaSync.sh
Last active July 31, 2019 06:40
Sync MySQL schema. This script doesn't delete table record if tables is exists AND if table doesn't exists, import table without record.
#!/bin/bash -eu
#
# This script can sync MySQL schema without `DROP TABLE`.
# And If table isn't exists, import tables from source.
#
# Finally there is a confirmation screen.
#
# Need these packages: mysql, mysqldump, mysqldiff
# GitHub: @rluisr
@augbog
augbog / Free O'Reilly Books.md
Last active May 14, 2024 10:27
Free O'Reilly Books

Free O'Reilly books and convenient script to just download them.

Thanks /u/FallenAege/ and /u/ShPavel/ from this Reddit post

How to use:

  1. Take the download.sh file and put it into a directory where you want the files to be saved.
  2. cd into the directory and make sure that it has executable permissions (chmod +x download.sh should do it)
  3. Run ./download.sh and wee there it goes. Also if you do not want all the files, just simply comment the ones you do not want.
@JonCole
JonCole / RedisKeyspaceNotificationsExample.cs
Last active December 22, 2023 00:27
Redis Keyspace Notification Example
using System;
namespace StackExchange.Redis
{
static class RedisKeyspaceNotifications
{
/// <summary>
/// NOTE: For this sample to work, you need to go to the Azure Portal and configure keyspace notifications with "Kxge$" to
/// 1) turn on expiration notifications (x),
/// 2) general command notices (g) and
@fevangelou
fevangelou / my.cnf
Last active May 25, 2024 19:49
Optimized my.cnf configuration for MySQL/MariaDB (on cPanel/WHM servers)
# === Optimized my.cnf configuration for MySQL/MariaDB (on cPanel/WHM servers) ===
#
# by Fotis Evangelou, developer of Engintron (engintron.com)
#
# ~ Updated December 2021 ~
#
#
# The settings provided below are a starting point for a 8-16 GB RAM server with 4-8 CPU cores.
# If you have different resources available you should adjust accordingly to save CPU, RAM & disk I/O usage.
#
@mugifly
mugifly / docker-container-ip.sh
Last active October 5, 2020 10:26
Simple inspector for Docker container IP address (shell script)
#!/bin/bash
# Simple inspector for Docker container IP address
# https://gist.github.com/mugifly/3bb1c54b48764340eda8
print_help () {
echo -e "USAGE: docker-container-ip.sh KEYWORD\n"
echo "KEYWORD: A keyword string for target container."
echo " e.g. dokku.mysql.foobar"
echo -e "\n[Example usecases]"
echo " Connect to MySQL database in container:"
@fdecampredon
fdecampredon / Contract.ts
Last active August 10, 2019 22:03
Contract programming with typescript and decorators
@In((a: string, b: string) => {
assert(typeof a === 'string');
assert(typeof b === 'string');
assert(a.length > 5);
assert(a.length > 7);
})
@Out((result: string) => {
assert(typeof result === 'string');
assert(a.length > 12);
})
@temmings
temmings / seperate.pl
Created January 29, 2015 15:55
Do "mysqldump --routines" to separate files. (fuzzy)
#!/usr/bin/perl
#
# mysqldump -routines --no-create-info --no-data --no-create-db --compact | perl $0
use strict;
use warnings;
use utf8;
my $output_dir = "out";
@jboner
jboner / latency.txt
Last active June 7, 2024 11:40
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@madd0
madd0 / queryString.cs
Created November 15, 2011 08:50
Create a URL query string from a NameValueCollection in C#
var nvc = new NameValueCollection
{
{ "key1", "value1" },
{ "key2", "value2" },
{ "key3", "" }
};
var builder = new UriBuilder("http://www.example.com");