Skip to content

Instantly share code, notes, and snippets.

View amayatsky's full-sized avatar

Alexander Mayatsky amayatsky

  • MTS - Mobile TeleSystems PJSC
  • Moscow
View GitHub Profile
@amayatsky
amayatsky / ObjectIdentifierHashable.swift
Last active March 31, 2020 11:01
Reusable Swift Extension to Make Any Class Hashable
protocol ObjectIdentifierHashable : class, Hashable {
}
extension ObjectIdentifierHashable {
static func ==(lhs: Self, rhs: Self) -> Bool {
return lhs === rhs
}
public func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self))
@amayatsky
amayatsky / XORCrypt.gradle
Last active March 13, 2019 09:23 — forked from premnirmal/XORCrypt.java
Simple yet effective XOR encryption
private static int[] encrypt(String str, String key) {
int[] output = new int[str.length()];
for(int i = 0; i < str.length(); i++) {
int o = ((int) str.charAt(i) ^ (int) key.charAt(i % (key.length() - 1))) + (char)('0');
output[i] = o;
}
return output;
}
@amayatsky
amayatsky / URL+Zip.swift
Last active June 9, 2018 07:01 — forked from marcprux/NSURL+Zip.swift
Categories on URL and Data to create a zip archive without any external dependencies
public extension URL {
/// Creates a zip archive of the file/folder represented by this URL and returns a references to the zipped file
///
/// - parameter dest: the destination URL; if nil, the destination will be this URL with ".zip" appended
func zip(dest: URL? = nil) throws -> URL {
let destURL = dest ?? self.appendingPathExtension("zip")
let fm = FileManager.default
var isDir: ObjCBool = false
@amayatsky
amayatsky / 2ch-hk-cleaner.js
Last active November 17, 2018 04:46
Remove all clutter from 2ch.hk but leave images, webm, mp4 and links intact
var atriExtensionLoader = function() {
var console = window.console || {
"log": function(ix) {}
};
console.log("AtriExtensions: revision 29");
if (window.$) {
console.log("AtriExtensions: $ " + $.fn.jquery);
} else {
console.log("AtriExtensions: $ missing");
return;
@amayatsky
amayatsky / NSString+KBAdditions.swift
Last active February 22, 2019 13:28 — forked from mkubenka/NSString+KBAdditions.h
Rewritten for Swift + UIButton extension
//
// NSString+KBAdditions.swift
//
// Created by Alexander Mayatsky on 16/03/16.
//
// Original code from http://stackoverflow.com/a/4383281/463892 & http://stackoverflow.com/a/18951386
//
import Foundation
import UIKit