Skip to content

Instantly share code, notes, and snippets.

View rodionovd's full-sized avatar
🗿
I'm slow

Dmitry Rodionov rodionovd

🗿
I'm slow
View GitHub Profile
- (void)scrollViewDidScroll:(UIScrollView *)sender {
BOOL isScrollingRight = _scrollView.contentOffset.x > _previousContentOffsetX;
_mostRecentScrollWasRight = isScrollingRight;
_previousContentOffsetX = _scrollView.contentOffset.x;
CGFloat pageWidth = _scrollView.frame.size.width;
int scrollingToPageNum = isScrollingRight ? (ceil((_scrollView.contentOffset.x - pageWidth) / pageWidth) + 1) : (floor((_scrollView.contentOffset.x -pageWidth) / pageWidth) + 1);
int percentOfScrollToPageOnscreen = isScrollingRight ? floor((((int)_scrollView.contentOffset.x % (int)pageWidth) / pageWidth)*100)
/* Copied, Pasted and summarized from ps' source code.
You can use sysctl to get other process' argv.
*/
#include <sys/sysctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define pid_of(pproc) pproc->kp_proc.p_pid
@mattstevens
mattstevens / gist:989296
Created May 24, 2011 18:15
Monitoring for IP address changes
#import "NetworkMonitor.h"
NSString *NetworkConfigurationDidChangeNotification = @"NetworkConfigurationDidChangeNotification";
void storeCallback(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) {
[(NetworkMonitor *)info update];
}
@implementation NetworkMonitor
@peon-pasado-zeitnot
peon-pasado-zeitnot / gist:1242279
Created September 26, 2011 13:53
This D-trace script lists all run programs with their arguments - works with OSX
#!/usr/sbin/dtrace -C -s
#pragma D option quiet
proc::posix_spawn:exec-success,proc::__mac_execve:exec-success
{
this->isx64=(curproc->p_flag & P_LP64)!=0;
#define SELECT_64_86(x64, x86) (this->isx64 ? (x64) : (x86))
#define GET_POINTER(base, offset) (user_addr_t)SELECT_64_86(*(uint64_t*)((base)+sizeof(uint64_t)*(offset)), *(uint32_t*)((base)+sizeof(uint32_t)*(offset)))
@brandonb927
brandonb927 / osx-for-hackers.sh
Last active May 14, 2024 18:00
OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned.
#!/bin/sh
###
# SOME COMMANDS WILL NOT WORK ON macOS (Sierra or newer)
# For Sierra or newer, see https://github.com/mathiasbynens/dotfiles/blob/master/.macos
###
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/5b3c8418ed42d93af2e647dc9d122f25cc034871/.osx
@nielsbot
nielsbot / procinfo.c
Created August 24, 2012 20:05
Get number of threads (running) in all tasks on OS X
#import <libproc.h>
#import <stdlib.h>
#import <stdio.h>
int main( int argc, const char * argv[])
{
pid_t * pids = calloc(0x4000, 1);
int count = proc_listallpids(pids, 0x4000);
printf("count=%u\n", count) ;
@zorgiepoo
zorgiepoo / leaksucks.c
Created March 5, 2014 02:21
task_for_pid() leak when dev ID signed
// task_for_pid leak
// **IMPORTANT** To reproduce this bug, you have to sign this program with a developer ID -- do not use a self-signed certificate or run as root!
// This code will cause taskgated's memory usage to grow (see activity monitor)
// Link to Xcode project with included info.plist: http://tinyurl.com/kps28av
// Radar 16230826
#include <mach/mach_init.h>
#include <mach/task.h>
#include <mach/mach_port.h>
@desertmonad
desertmonad / 32.asm
Last active November 26, 2018 13:00 — forked from FiloSottile/32.asm
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The .data section is for storing and naming constants.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
section .data
msg: db "Hello world!", 10
.len: equ $ - msg
@SheffieldKevin
SheffieldKevin / movietransitions.swift
Last active June 25, 2021 16:58
Make a movie with transitions with AVFoundation and swift
//
// main.swift
// mutablecomposition
//
// Created by Kevin Meaney on 24/08/2015.
// Copyright (c) 2015 Kevin Meaney. All rights reserved.
//
import Foundation
@sharplet
sharplet / rake.log
Last active September 12, 2022 12:24
Building a Swift framework, then building and running Quick specs, *without Xcode*
# View on GitHub: https://github.com/sharplet/Switch
# Try it yourself: git clone https://github.com/sharplet/Switch.git && cd Switch && rake
$ rake
mkdir -p Build
mkdir -p Build/Switch.framework
mkdir -p Build/Switch.framework/Versions/A/Modules/Switch.swiftmodule
ln -sf A Build/Switch.framework/Versions/Current
ln -sf Versions/Current/Modules Build/Switch.framework/Modules
ln -sf Versions/Current/Switch Build/Switch.framework/Switch
xcrun -sdk macosx swiftc -module-name Switch -emit-library -o Build/Switch.framework/Versions/Current/Switch -- Source/Array+Ext.swift Source/Option.swift Source/ParseResult.swift Source/Parser.swift Source/String+Ext.swift