Skip to content

Instantly share code, notes, and snippets.

View xhruso00's full-sized avatar

Marek Hrusovsky xhruso00

  • Bratislava, Slovakia
View GitHub Profile
@xhruso00
xhruso00 / gist:5fe72ec211293d4bff7b
Created February 22, 2015 05:34
Code snippet to find the number of pairs given by the difference in given array of unique numbers
int numberOfPairs(NSSet *uniqueNumbers, int difference) {
if (difference <= 0 || [uniqueNumbers count] <= 0) {
return 0;
}
//creating set of decremented numbers to do intersection
NSMutableSet *setToCompare = [[NSMutableSet alloc] init];
for (NSNumber *number in uniqueNumbers) {
[setToCompare addObject:@([number intValue] - difference)];
}
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
@xhruso00
xhruso00 / gist:c382dda3f07dcb7f5897
Created August 29, 2014 12:48
NSTableView example that treats TAB & ENTER keystroke as special command
//Subclass NSTableView and override the textDidEndEditing method. Then change the custom class of NSTableView instance in IB to the subclass.
- (void) textDidEndEditing: (NSNotification *) notification
{
NSInteger editedColumn = [self editedColumn];
NSInteger editedRow = [self editedRow];
NSInteger lastRow = [self numberOfRows];
NSInteger lastCol = [self numberOfColumns];
NSDictionary *userInfo = [notification userInfo];
int textMovement = [(NSNumber *)[userInfo valueForKey:@"NSTextMovement"] intValue];
[super textDidEndEditing: notification];
@xhruso00
xhruso00 / osx.sh
Created July 23, 2014 15:49 — forked from edsonaj/osx.sh
#!/bin/bash
# Based on https://github.com/mathiasbynens/dotfiles/blob/master/.osx
###############################################################################
# General UI/UX #
###############################################################################
# Set computer name (as done via System Preferences → Sharing)
scutil --set ComputerName "Edson Alves Junior's MacBook Pro"
scutil --set HostName "Edson Alves Junior's MacBook Pro"
@xhruso00
xhruso00 / BlackAndWhiteThreshold.metal
Last active February 27, 2021 21:12
Black & White monochrome 1bit threshold filter. Uses modern 10.15 approach with protocols and metal and half data type. To use simply call [CIFilter blackAndWhiteThresholdFilter]; (add -fcikernel to "Other metal compiler flags" and add -cikernel for User-defined MTTLINKER_FLAGS . Enable fast math in build settings section metal. Targeting earlie…
#include <metal_stdlib>
using namespace metal;
//https://en.wikipedia.org/wiki/List_of_monochrome_and_RGB_palettes
//https://en.wikipedia.org/wiki/Relative_luminance
//https://en.wikipedia.org/wiki/Grayscale
constant float3 kRec709Luma = float3(0.2126, 0.7152, 0.0722);
constant float3 kRec601Luma = float3(0.299 , 0.587 , 0.114);
//constant float3 kRec2100Luma = float3(0.2627, 0.6780, 0.0593);
@xhruso00
xhruso00 / gist:9931144
Created April 2, 2014 09:49
Affiliate helper: StoreFrontId per country code, list of PHG supported countries, list of TradeDoubler supported countries
+ (NSArray *)tradeDoublerSupportedCountryCodes {
return @[@"AR", @"AT", @"BE", @"BR", @"BG", @"CL", @"CO", @"CR", @"CY", @"CZ", @"DK", @"SV", @"EE", @"FI", @"FR", @"DE", @"GR", @"HN", @"HU", @"IE", @"IT", @"LV", @"LT", @"LU", @"MT", @"NL", @"NO", @"PA", @"PY", @"PE", @"PL", @"PT", @"RO", @"SK", @"SI", @"ES", @"SE", @"CH", @"GB"];
}
+ (NSArray *)PHGSupportedCountryCodes {
return @[@"AI", @"AG", @"AR", @"AM", @"AU", @"AT", @"BS", @"BH", @"BB", @"BY", @"BE", @"BZ", @"BM", @"BO", @"BW", @"BR", @"VG", @"BN", @"BG", @"BF", @"CA", @"CV", @"KY", @"CL", @"CO", @"CR", @"HR", @"CY", @"CZ", @"DK", @"DM", @"EC", @"EG", @"SV", @"EE", @"FJ", @"FI", @"FR", @"GM", @"DE", @"GH", @"GR", @"GD", @"GT", @"GW", @"GY", @"HN", @"HK", @"HU", @"IN", @"ID", @"IE", @"IL", @"IT", @"JM", @"JP", @"JO", @"KZ", @"KE", @"KW", @"KG", @"LV", @"LB", @"LT", @"LU", @"MO", @"MK", @"MY", @"MT", @"MU", @"MX", @"FM", @"MN", @"MZ", @"NA", @"NP", @"NL", @"NZ", @"NI", @"NE", @"NG", @"NO", @"OM", @"PK", @"PA", @"PG", @"PY", @"PE", @"PH", @"PL", @
#Watch symlinks (ls -al)
codesign --verbose=4 --deep --strict Mail.app/
--prepared:/Applications/Mail.app/Contents/PlugIns/MailWebPlugIn.webplugin
--validated:/Applications/Mail.app/Contents/PlugIns/MailWebPlugIn.webplugin
Mail.app/: valid on disk
Mail.app/: satisfies its Designated Requirement
#http://furbo.org/2015/07/23/code-signing-in-el-capitan/
codesign --verbose=4 --deep --strict xScope.app
@xhruso00
xhruso00 / gist:8861083
Created February 7, 2014 11:29
Applescript to reset Contacts / AddressBook privacy& security list. Requires administration password.
tell application "System Preferences"
launch
activate
reveal anchor "Privacy_Contacts" of pane id "com.apple.preference.security"
display alert "RESET CONTACTS APPROVAL LIST" message "This script will reset (clear) the list of applications in the Contacts section of the Privacy system preference pane." & linefeed & linefeed & "This action requires an administrative password, and cannot be undone." as critical buttons {"Cancel", "Reset"} cancel button "Cancel"
set show all to true
@xhruso00
xhruso00 / hosts + curl command
Created September 15, 2013 07:48
iTunes store crawling (data mining)
The trick is to set "Host:itunes.apple.com" as a header and disable certification verification "-k"
Optionally use "-v" for verbose outcome
When itunes detects your crawling and returns blank page just swap the IP address.
curl -silent -k -A "iMacAppStore/1.0.1 (Macintosh; U; Intel Mac OS X 10.6.7; en) AppleWebKit/533.20.25 " --anyauth -H "Host:itunes.apple.com" -v "https://88.221.6.217:443/WebObjects/MZStore.woa/wa/viewSoftware?mt=12&id=491390884&cc=us"
List of IP addresses:
88.221.6.217 itunes.apple.com
2.21.34.217 itunes.apple.com
95.100.210.217 itunes.apple.com