Skip to content

Instantly share code, notes, and snippets.

View beltex's full-sized avatar

Omeed beltex

View GitHub Profile
@marcan
marcan / linux.sh
Last active December 1, 2023 15:18
Linux kernel initialization, translated to bash
#!/boot/bzImage
# Linux kernel userspace initialization code, translated to bash
# (Minus floppy disk handling, because seriously, it's 2017.)
# Not 100% accurate, but gives you a good idea of how kernel init works
# GPLv2, Copyright 2017 Hector Martin <marcan@marcan.st>
# Based on Linux 4.10-rc2.
# Note: pretend chroot is a builtin and affects the current process
# Note: kernel actually uses major/minor device numbers instead of device name

Principles of Adult Behavior

  1. Be patient. No matter what.
  2. Don’t badmouth: Assign responsibility, not blame. Say nothing of another you wouldn’t say to him.
  3. Never assume the motives of others are, to them, less noble than yours are to you.
  4. Expand your sense of the possible.
  5. Don’t trouble yourself with matters you truly cannot change.
  6. Expect no more of anyone than you can deliver yourself.
  7. Tolerate ambiguity.
  8. Laugh at yourself frequently.
@NSExceptional
NSExceptional / Private class usage in Swift.md
Last active February 21, 2022 22:40
An example of how to use a private class from Swift. It's not pretty, but it isn't too bad.

Using private Objective-C classes from Swift

In Objective-C, if you want to make use of one of Apple's internal classes, all you have to do is declare the class's interface with the methods you want to use. From there you can create instances of the class by using the NSClassFromString function to obtain a reference to the class object, like so:

[[NSClassFromString(@"_NSSomeClass") alloc] initWithFoo:5]

In Swift, this is not so easy. Referencing the type of the "hollow" Objective-C class interface anywhere in Swift code makes the compiler query the class for type information that is not known at compile time. This presents a huge problem. You cannot dynamically initialize a type either. Though, it seems the following code used to work at one point:

@joepie91
joepie91 / vpn.md
Last active April 20, 2024 21:15
Don't use VPN services.

Don't use VPN services.

No, seriously, don't. You're probably reading this because you've asked what VPN service to use, and this is the answer.

Note: The content in this post does not apply to using VPN for their intended purpose; that is, as a virtual private (internal) network. It only applies to using it as a glorified proxy, which is what every third-party "VPN provider" does.

  • A Russian translation of this article can be found here, contributed by Timur Demin.
  • A Turkish translation can be found here, contributed by agyild.
  • There's also this article about VPN services, which is honestly better written (and has more cat pictures!) than my article.
@karpathy
karpathy / min-char-rnn.py
Last active April 23, 2024 17:55
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@mbalex99
mbalex99 / gist:8802db1695f20c520ca0
Last active May 22, 2022 11:58
Alamofire and RxSwift
let rx_request = Observable<Value>.create { (observer) -> Disposable in
let requestReference = Alamofire.request(.POST, url, parameters: payload)
.responseJSON(completionHandler: { (response) in
if let value = response.result.value {
observer.onNext(value)
observer.onCompleted()
}else if let error = response.result.error {
observer.onError(error)
}
})
@nicklockwood
nicklockwood / gist:21495c2015fd2dda56cf
Last active August 13, 2020 13:57
Thoughts on Swift 2 Errors

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post:

@iraycd
iraycd / horrible-storyboard.md
Created June 10, 2015 14:20
Bad Experiences with Storyboard.

Interestingly Apple doesn't even use Storyboards in their recently open-sourced ResearchKit as [Peter Steinberger has noticed][1] (under the subheading "Interface Builder").

As expected, Apple keeps improving Storyboards and Xcode. Some of the points that applied to iOS 7 and below don't apply to iOS 8 anymore (and are now marked as such). So while Storyboards inherently still have flaws, I revise my advice from don't use to selectively use where it makes sense.

Even now that iOS 7 is out, I would advise against to use caution when deciding whether to use Storyboards. Here are my reasons:

  • Storyboards fail at runtime, not at compile time: You have a typo in a segue name or connected it wrong in your storyboard? It will blow up at runtime. You use a custom UIViewController subclass that doesn't exist anymore in your storyboard? It will blow up at runtime. If you do such things in code, you will catch them early on, during compile time. Update: My new tool **[StoryboardLin
@TimOliver
TimOliver / UIScrollView+ZoomToPoint.m
Last active November 23, 2022 09:14
Zooming to a specific CGPoint inside a UIScrollView (2015 Edition)
@implementation UIScrollView (ZoomToPoint)
/**
Zooms into the specified point of the scroll view's zoomable content view at the supplied scaled.
(The zoomable content view is the view that is returned in `viewForZoomingInScrollView:`
@param zoomPoint - In terms of the scroll view's co-ordinate space, the point to zoom to
@param scale - A value between minimumZoomScale and maximumZoomScale in which to zoom to.
@param animated - Whether the transition is animated, or instant
@mpasternacki
mpasternacki / freebsd_on_mbp.md
Created January 23, 2015 17:12
FreeBSD on a MacBook Pro

FreeBSD on a MacBook Pro

Since 2008 or 2009 I work on Apple hardware and OS: back then I grew tired of Linux desktop (which is going to be MASSIVE NEXT YEAR, at least since 2001), and switched to something that Just Works. Six years later, it less and less Just Works, started turning into spyware and nagware, and doesn't need much less maintenance than Linux desktop — at least for my work, which is system administration and software development, probably it is better for the mythical End User person. Work needed to get software I need running is not less obscure than work I'd need to do on Linux or othe Unix-like system. I am finding myself turning away from GUI programs that I used to appreciate, and most of the time I use OSX to just run a terminal, Firefox, and Emacs. GUI that used to be nice and unintrusive, got annoying. Either I came full circle in the last 15 years of my computer usage, or the OSX experience degraded in last 5 years. Again, this is from a sysadmin/developer ki