🪼
Stranger Things
Cosmic Funnies
2025 on Tumblr: Trends That Defined the Year
AnasAbdin
tumblr dot com
let's talk about Bridgerton tea, my ask is open
Sade Olutola

roma★
trying on a metaphor
wallacepolsom
Today's Document

⁂
Peter Solarz

pixel skylines

titsay

JVL
he wasn't even looking at me and he found me
DEAR READER
No title available
seen from France
seen from India

seen from Netherlands
seen from United Arab Emirates
seen from Iraq
seen from Azerbaijan

seen from Azerbaijan
seen from Azerbaijan
seen from United States
seen from United States

seen from T1
seen from United States
seen from United States
seen from United States
seen from United States
seen from United States
seen from United States

seen from Malaysia

seen from France

seen from Netherlands
@keitaiosblog
jj escaping for your laziest pinkies
This post is about customizing vim key maps on Atom editor. Since the exact solution was not hit much with googling, I leave a note here how to add a custom key map to Atom editor's vim-mode.
Among 10 fingers of mine, my pinkies are laziest. These dudes don't want to move as much as possible. When I need to type return key and delete key, my right pinky gets me to type ctrl-j and ctrl-h. Just so you know, my caps lock key is mapped to ctrl key, so that my left pinky doesn't have to move much. How lazy.
When I use vim, the most frequent used key map is "j j", escaping insert-mode to normal mode. This let you change back and forth between normal-mode and insert-mode quickly. Here is how to set it up.
Install vim-mode. I added it from Packages Settings in Atom. Search "vim-mode" and install it.
I found the solution in this quite long issue page. Thanks @kylesezhi!
Open keymap.cson file. you can open it by selecting "Keymap" in Atom menu at the top menu bar.
Add the following:
'atom-text-editor.vim-mode.insert-mode': 'j j': 'vim-mode:activate-normal-mode'
This means like, for insert-mode of Atom's vim-mode, add "j j" key map to a command activating normal mode, which means go back normal mode from insert mode. Note that the the key map is "j j", not "jj". A white space needs to be between js (pronounce jay-ze, it's not jay-es nor a rapper's name).
Save and re-launch Atom, and voilà! Now you can switch between normal-mode and insert-mode by typing j j. No more typing ctrl-c or esc.
Solution for an issue CocoaPods 0.39.0 does not work with Ruby 2.3.0 “NoMethodError - undefined method `to_ary'”
Have you seen the following error recently when you ran "pod install"?
"NoMethodError - undefined method `to_ary'..."
This error occurs when CocoaPods is run with Ruby 2.3.0, because Ruby 2.3.0 is not supported by CocoaPods 0.39.0. CocoaPods 1.0.0 (since beta 1) supports Ruby 2.3.0. There are 3 solutions.
Update CocoaPods to version 1.0.0 (the latest version is 1.0.0.beta.6).
Use a Ruby version prior to 2.3.0. You can install different versions of Ruby in your machine with RVM or rbenv.
Use CocoaPods desktop app. CocoaPods app uses 1.0.0.beta version of CocoaPods.
I tried CocoaPods desktop app, and it worked well with no problem :) If you don't want to change your dev enviornment, especially CocoaPods version 1.0.0 is still beta, and you want to stick with a release version, You should give it a shot. You can keep your version, while using version 1.0.0 by CocoaPods desktop app.
How to get started with Monoid, Functor & Monad in Swift
Last Thursday, I went to Swift Language User Group meetup hosted by Realm. The one of talks was titled "Understand Monads with this One Weird Trick" presented by Andy Bartholomew. It was a great talk. He explained really well. It was fascinating for me because I've been reading Functional Swift recently to learn how to code in Swift the functional way. The recorded talk video and slide will be online in a few weeks probably, but I leave a short note here with my memory before that.
Compared to Objective-C, one of the great and interesting features of Swift is that Functional Programming characteristic. As many people mentioned already online, Swift is heavily inspired Functional Programming, even though you can write code in Swift with a normal way (well, what is the normal way though? I don't know :) ) But, Functional Programming concenpt is way harder to understand, at least for me. In the FP world, there are many terms that we (object oriented programmer?) don't see usually. Most well-known ones are Monoid, Functor, Monad. (To be honest, I didn't know Monoid 😜 though) These new words are kind of scary for FP beginners. How can we learn these? How can we be friends with them?
Andy showed us in the talk how to write Monoid, Functor, Monad in Swift. He tried to convert these types into Swift types. He often said in the talk, "naming matters". To get to know them more easily, he reanamed three of the types based on their functionalities.
Monoid -> Concatenatable (if I remember correctly 😅)
Functor -> Mappable
Monad -> FlatMappable
This is great. renaming surprisingly helps me get to know what they are briefly. I had totally no idea with Monoid, Functor, Monad, but I know map and flatMap. This definitely helped me to grasp the main idea of each. Monad and I can be BFF now :D
At last, I leave here some links to pages explaining FP ideas well that I found.
http://www.mokacoding.com/blog/functor-applicative-monads-in-pictures
http://learnyouahaskell.com (Learning Haskell could be a good way learning Functional Programming I think...)
https://www.objc.io/books/functional-swift/ (This books is amazing. It's still not easy to understand the whole thing, but it explains Functional way Swift with easy examples and advanced techiniques.)
I am totally a Functional Programming noob. Something I mentioned in this post might be wrong. Please let me know if you find my mistakes, and misunderstanding.
NSCoding Protocol Implementation in Swift
I was working on Core Data today. I edited an entity attribute to have my custom class as a property, and updated its class file. I ran the app, and then it got crashed!
Why? Because My custom class was not conformed NSCoding protocol. If I remember correctly (well I should have searched more beforehand), Core data uses Key Value Coding (aka. KVC) system for persisting objects. When an entity object is created from the Core Data model graph (I don't know how it is called honestly), you don't need to worry about anything. But, when you make your custom class by yourself, and set it to a property of a subclass of NSManagedObject, you need to make the class to be conformed to NSCoding protocol, so that the class is able to be encoded and decoded. Another use case is when objects are sent via WCSession from iOS to watchOS.
So, I wrote the implementation how to conform to NSCoding protocol. It's actually quite easy. You need to implement just 2 required methods of NSCoding protocol. Here is the snippet. I wrote it with Swift this time.
Access CFDictionaryRef in ABAddressBook
There are not many resources online about accessing a CFDictionaryRef. It's not the same as an NSDictionary because of CFTypeRef types. It gets even worse, it's in an ABAddressBook.
The structure in the ABRecord in an ABAddressBook is like this: addressBook -> records -> record -> addresses -> address -> city
The point is the addresses are of type ABMultiValueRef. To access a single address you need to do subscript it with a C-style function. To get the city value from the CFDictionaryRef address, the easiest and most familiar way is to type cast from a CFDictionaryRef to an NSDictionary. It should be quite easy to access them now!
Fixed grammar mistakes. Thanks @bhelyer for correcting them!
How to update a record’s address with ABAddressBook framework
I coded with ABAddressBook today. Even though ABAddressBook is deprecated from iOS 9, and replaced with Contacts framework, some people like me still needs to use it because of keeping supporting iOS 8.
When you code with ABAddressBook, you need to deal with Core Foundation types, like CFTypeRef. CFTypeRefs are a little bit different from other normal Foundation types. When you use them, you should be careful about the following:
Don't forget CFRelase(object);
The Create/Copy rule, and The Get rule.
(__bridge Type), (__bridge_retain Type), (__bridge_release Type)
NSString vs. CFStringRef, toll-free types
Very tedious way creating a new CFDictionaryRef
Here is the gist how to update address of a record in address book. For more details, check out Apple's Address Book Programming Guide for iOS.
How to embed gist in Tumblr 2016
Google gave me some links to the way adding some js libaries to tumblr's header tag. But these solutions are pretty old. And It looks like it's got very easy now.
Please check out the attachment screenshot of a part of gist page. On top-right corner, there is sharable link text field. It' already shown with "Embed". Copy the embed link, and paste it in a tumblr blog post, then voila! Your tumblr post should be displayed with a pretty gist with ❤️ by GitHub :)
How to get the class name of an object in Swift 2
Super simple :)
An observation on Objective-C
(This post was originally posted in October of 2009 and has been reposted here for posterity)
I was thinking recently on the idea of “sending a message” versus that of “calling a method”. Those familiar with the capabilities of the Objective-C runtime understand that there is a difference.
Method Calling
Most compiled languages refer to methods and functions internally as offsets. The offset indicates that if one were to move a certain number of spaces in memory from a designated starting point, then we would find the beginning of the instructions that correspond to the desired function.
This has the advantage of being very fast. The starting point is known at compile-time, and so to find the appropriate section of memory takes just a couple of instructions. However, it has the disadvantage of being inflexible. This is where most compiled languages differ from Objective-C.
Message Sending
The Objective-C runtime maintains a list of all the methods and functions it knows about. The list has two components per entry: the name of the method (known as the method’s “selector”) and the location of the method in memory.
When an object attempts to “call a method”, it is really behaving quite differently. When the code was compiled, the compiler translated the code [anObject doMethod:aParameter]; into objc_msgSend(anObject, @selector(doMethod:), aParameter); (basically. The actual behavior is slightly more complex but is all explained in the documentation).
The objc_msgSend() function does a dynamic lookup. It knows the name of the method it’s supposed to find (@selector(doMethod:)), and so it goes and looks up in its big list where it can find what it’s supposed to do next.
This allows us to do some really interesting things. For example, we can modify this list whenever we want. We can swap out values of the list, so that instead of selector A executing the code for A, selector A might instead point to the code for B. The runtime allows us to do some very powerful stuff.
The disadvantage is that this is (as you might imagine) slightly slower than directly jumping to the appropriate section in code. However, the difference is minute. Each message send takes just a couple nanoseconds longer than a regular method call.
Why this is so cool
In addition to dynamically modifying the runtime lookup table, the runtime does some other really nice things for us. For example, before it sends a message, it first asks the object if it even recognizes the method to begin with. The object can dynamically choose whether it wants to accept a message! The object can also choose to forward the message on to a different object. The object can also choose to execute different code for a specific method.
In other words, when we send a message, we don’t have any guarantee that 1) the method we’re intending to call is actually the method that will be called and 2) the object we’re intending to message is the one that will end up responding.
Usually, things work out as we expect. However, the runtime allows us to be exceptionally dynamic. This led me to make the following connection:
Calling a method is analogous to the active voice. Sending a message is analogous to passive voice.
(Or for you SAT-minded people: Calling a method :: Active voice ⇆ Sending a message :: Passive voice)
A brief lesson in grammar
In English (and most other languages), there are two ways we can associate a verb (an action) with a noun (the doer). One is with the active voice. For example: “The object did something.” In this construction there is no ambiguity as to who is performing. The doer takes full responsibility and accountability for performing the action. Likewise, when we use statically compiled languages that use offsets to immediately jump to the proper place in code, there is never any ambiguity as to what is going to happen. We know exactly which object is going to be executing the code, and we know exactly what code is going to be executed.
The other way we can construct sentences is using the passive voice. In this case, the sentence gets flipped around, like so: “Something was done by the object.” The emphasis is no longer on “the object”, but rather on what the object is supposed to be doing: “something.” If we leave off the noun, and just say “Something was done”, we know that something happened, but we have no idea who by. This is similar to sending a message in Objective-C (and other similar languages). When we send a message, we’re never totally sure that the person we want to respond to the message is the one who will actually respond. Instead, the focus is more on the message itself. We want something specific to happen, but as long as it gets done, we don’t really care who does it.
While the comparison itself to different voices in grammar isn’t itself very important, it is important to understand what the runtime is doing and how it is doing it. Understanding this allows us to do some really cool things in Objective-C that are not easily possible in other languages without significant amounts of work.
Downgrading iOS Development Target & Cocoapods
UPDATE
Actually, it didn't work unfortunately. It'S becuase of Xcode version. :(
=============================
I just had a little bit problem with iOS Development Target & Cocoapods. I leave a note here how to fix it.
What happened and How it happened
I built a small demo project with iOS Development Target 9.0 on Xcode 7. This app has AFNetworking v2.6.0 added via Cocoapods. However, I needed to downgrade its iOS Development Target to 8.4. I just went to the project settings and changed it. Then, I got many yellow warnings like the below:
ld: warning: object file (/path/to/DerivedData/something) was built for newer iOS version (9.0) than being linked (8.4)
The demo app was still able to be built. Why did these warnings appear? My guess was Cocoapods Podfile settings caused this problem. I didn't write any platform settings in Podfile. Cocoapods automatically set some pod settings to iOS 9.0. This settings didn't get changed even by changing iOS Development Target.
How I fixed
I updated Podfile to the following:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.4' pod 'AFNetworking', '2.6.0'
I jsut added the platform setting. Then, ran pod update on the Terminal. Also, I deleted DerivedData & the app on the iOS Simulator. These completely fixed all warning issues!
Selection Sort in Objective-C
I wrote the selection sort method in Objective-C. This post will be updated later by adding the Swift version.
A key point of selection sort is when the array is checked for minimum value, searching is started from the next index to the current one. This makes when iteration goes on, elements get reduced.
Reference: https://www.khanacademy.org/computing/computer-science/algorithms/sorting-algorithms/p/challenge-implement-selection-sort
Binary Search in Objective-C
I will post about algorithms with Objective-C & Swift as I learn them. This is the first one of the series. I coded the Objective-C version of Binary Search. I will post the Swift version tomorrow.
There is one tricky point: while statement needs to be the following.
while (minIndex <= maxIndex) { // check numbers... }
If it is like (minIndex < maxIndex), the binary search can’t check at the end of elements, array[0] and array[n-1]. Watch out.
Here is my binary search code.
Reference: https://www.khanacademy.org/computing/computer-science/algorithms/binary-search/p/challenge-binary-search
How I learn Haskell - Part 1: Haskell Hack Night AND Lesson 1 Haskell Course
Tonight I went to Haskell Hack Night organized by Bay Area Haskell Users Group at Wagon HQ. Ryan Orendorff gave us, Haskell newbies, the intro haskell class based on CIS 194. Some people were Haskell beginners, and some of others were hacking their own Haskell projects. Actually, I just found this meetup today, and jumped in it. It was fast pace lecture, Ryan tried to give us a summary tour of basic Haskell rules, so, I was overwhelmed. But I am happy I finally learned the syntax :: means "of type". It was really unfamiliar for me who have coded only Objective-C and Swift. I am very satisfied now :) I leave the following links and notes to get started coding Haskell. Next meetup is in 2 weeks. Hope I will keep learning Haskell little by little.
Haskell website: https://www.haskell.org
To get started coding Haskell, I need to install Haskell Platform (probably it's like IDE?): https://www.haskell.org/platform/mac.html
Also compiler GHC needs to be installed: https://www.haskell.org/downloads/osx
There is GHCi, like Playground for Swift: https://wiki.haskell.org/GHC/GHCi
Online IDE: https://www.fpcomplete.com
Also, online GHCi: http://ghc.io
Recommended learning resource: http://learnyouahaskell.com/chapters
I just started learning Haskell. There might be some mistakes. Please let me know if you find any. I am really excited to learn another new programming language.
Problem with code syntax highlighting in Tumblr’s Markdown
Customizing my new Tumblr blog to display code nicely, so I'm trying to add code syntax highlighting feature.
GitHub Flavored markdown has an easy syntax for code blocks.
Code blocks can be taken a step further by adding syntax highlighting. In your fenced block, add an optional language identifier and we'll run it through syntax highlighting. For example, to syntax highlight Ruby code:
require 'redcarpet' markdown = Redcarpet.new("Hello World!") puts markdown.to_html
We use Linguist to perform language detection and syntax highlighting. You can find out which keywords are valid by perusing the languages YAML file.
https://help.github.com/articles/github-flavored-markdown/#syntax-highlighting
...I can't even quote code blocks well. Anyway, to make code to be displayed as code blocks, I can write my code with triple back-ticks and programming language name with GitHub's Markdown. And, with Linguist or highlight.js or google code-prettify, I could make code syntax highlighting with this markdown code blocks syntax (too many syntax!). However, and as you see, It seems a programming language specifier doesn't work in Tumblr. language name is shown a part of code, like the below:
NSString *tripleBackTicksString = [[NSString alloc] init];
This is not what I meant. Current workaround is like the below.
NSString *string = [[NSString alloc] init];
I used html tags, pre tag and code tags with class attribute of Objective-C. But, I am writing with Markdown because I don't want to use html tags. Unfortunately, my brain doesn't work well anymore at 4am. I will look for a right solution after having some sleep.
P.S. I am looking forward to seeing new things from Apple's announcement :)
Test Post
This is a test post
Hello. This is a test post, so it will be deleted later. Thanks!
Inline code has back-ticks around it.
NSString *string = [[NSString alloc] init];
NSString *string = [[NSString alloc] init];
keita2
Keita