Skip to content

Instantly share code, notes, and snippets.

@Nihisil
Nihisil / jail.local
Last active September 5, 2023 06:20
Send notifications to the Slack from fail2ban
...
action_with_slack_notification = %(banaction)s[name=%(__name__)s, port="%(port)$
slack[name=%(__name__)s]
action = %(action_with_slack_notification)s
...
@niun
niun / find-raspberry.sh
Last active September 16, 2022 12:06
Find Raspberry Pi in network (looking for MAC address vendor prefix of Raspberry Pi Foundation using nmap, awk for ipv4 / ping6, ip, grep for ipv6 neighbour discovery)
sudo nmap -sP 192.168.0.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
@0xced
0xced / pin256.sh
Created August 30, 2017 14:50
Extract certificate + public key + pin from a TLS server
#!/usr/bin/env bash -e
HOST=${1:-cloudflare.com}
FILENAME=${2:-${HOST%%.*}}
# For file naming, see https://support.ssl.com/Knowledgebase/Article/View/19/0/der-vs-crt-vs-cer-vs-pem-certificates-and-how-to-convert-them
# For HTTP Public Key Pinning (HPKP), see https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning
CERTIFICATE_PEM="${FILENAME}_certificate.ascii.crt"
CERTIFICATE_DER="${FILENAME}_certificate.crt"
PUBKEY_PEM="${FILENAME}_pubkey.ascii.key"
@msealand
msealand / CGVectorUtilities.swift
Last active September 4, 2019 17:37
Operator overloads to do scalar vector math on CGPoint, CGSize, CGVector.
import CoreGraphics
protocol VectorType {
typealias Element
var xElement: Element { get }
var yElement: Element { get }
class func buildFrom(#x: Element, y: Element) -> Self
@sjoerdvisscher
sjoerdvisscher / minimal.swift
Created June 28, 2017 14:42
Using Decodable to generate a minimal value
struct MinimalDecoder : Decoder {
var codingPath = [CodingKey?]()
var userInfo = [CodingUserInfoKey : Any]()
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self))
}
public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
return DecodingContainer(decoder: self)
@Catfish-Man
Catfish-Man / lockcachecontention.m
Last active July 5, 2017 07:00
Benchmark showing how locks sharing a cache line will contend with each other
#import <Foundation/Foundation.h>
#import <time.h>
#import <os/lock.h>
#define ITERS 2000
#define NSEC_PER_ITER(time) (((double)time * (double)NSEC_PER_SEC) / (double)ITERS)
#define TEST(body, name) do {\
start = [NSDate date];\
for (int i = 0; i < ITERS; i++) {\
@henry0312
henry0312 / mingw.sh
Created November 27, 2011 06:19
Build MinGW Cross Compiler on Mac OS X Lion
#!/bin/sh
# 初期設定
WORK=$HOME/Builds/GCC
PREFIX=$HOME/mingw
export PATH="$HOME/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
# ソースコードのダウンロード
if [ ! -d $WORK/src ] ; then
mkdir src
@0xced
0xced / MoviePlayerControllerDoneButton.h
Created December 17, 2014 09:54
Access the "Done" button of a MPMoviePlayerController
#import <MediaPlayer/MediaPlayer.h>
/**
* Example usage:
* UIButton *doneButton = MoviePlayerControllerDoneButton(moviePlayerViewController.moviePlayer);
* [doneButton setTitle:@"✖" forState:UIControlStateNormal];
* doneButton.titleLabel.font = [UIFont systemFontOfSize:30];
*/
extern UIButton * MoviePlayerControllerDoneButton(MPMoviePlayerController *moviePlayerController);
@rupey
rupey / gist:f1429adab0877506c9fb
Created August 10, 2014 01:34
iTunes Store API rating count retriever snippet
#pragma mark - iTunes Store API
#define ITUNES_APP_ID @"870393074"
- (void)updateReviewCount
{
NSString *countryCode = [[[NSLocale currentLocale] objectForKey: NSLocaleCountryCode] lowercaseString];
NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/%@/lookup?id=%@", countryCode, ITUNES_APP_ID];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];