Skip to content

Instantly share code, notes, and snippets.

View gabrielribeiro's full-sized avatar

Gabriel Ribeiro gabrielribeiro

View GitHub Profile
@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:

@tsrivishnu
tsrivishnu / gitignore_already_tracked_file.md
Last active August 12, 2024 11:30
Git: Ignore already checked in file

Git: How can I ignore a file that is already committed to the repo?

You have a repo and quite some developers have cloned the repo and working on it. Now you want to add a file to gitignore which is already checked-in or tracked by Git.(The file is already commited into the repo)

Below are the steps on how to ignore this file (lets say the filename is config.py):

  • Add it to .gitignore:

$ echo "config.py" >> .gitignore

@edirpedro
edirpedro / wp_instagram_feed.php
Last active July 18, 2023 17:07
Function to get Instagram feed and cache it on WordPress
/*
* WP Instagram Feed
*
* To get a new Access Token, change the [], put it in the browser and it will return with your token in the next URL.
* https://instagram.com/oauth/authorize/?client_id=[CLIENT_ID]&redirect_uri=[REDIRECT_URL]&response_type=token
*********************************************************************/
function wp_instagram_feed($count = 20) {
$slug = "instagram_feed_self";
$access_token = '[ACCESS_TOKEN_HERE]';
@ollieatkinson
ollieatkinson / HTTPStatusCode.swift
Last active April 12, 2025 22:44
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational
@briansmith
briansmith / how-to-generate-and-use-private-keys-with-openssl-tool.md
Last active March 21, 2025 11:43
How to generate & use private keys using the OpenSSL command line tool

How to Generate & Use Private Keys using OpenSSL's Command Line Tool

These commands generate and use private keys in unencrypted binary (not Base64 “PEM”) PKCS#8 format. The PKCS#8 format is used here because it is the most interoperable format when dealing with software that isn't based on OpenSSL.

OpenSSL has a variety of commands that can be used to operate on private key files, some of which are specific to RSA (e.g. openssl rsa and openssl genrsa) or which have other limitations. Here we always use

@cyborch
cyborch / Date+NSDate.swift
Created May 4, 2017 08:56
Convert NSDate to Swift Date
import Foundation
extension Date {
init(date: NSDate) {
self.init(timeIntervalSinceReferenceDate: date.timeIntervalSinceReferenceDate)
}
}

Note

Apple will reject apps that are using private url schemes (Ugh, Apple....) if they are pretty much obvius. Some apps are rejected and others are not, so, be aware of this issue before implementing any of those URL's in your app as a feature.

Updates

  • [UPDATE 4] iOS 10 update: apparently settings now can be reached using App-Pref instead of prefs
  • [UPDATE 3] For now you just can use url schemes to open your apps's settings with Swift 3.0 (Xcode 8). I'll keep you informed when OS preferences can be reached
  • [UPDATE 2] The openURL() method of UIApplication is now deprecated. You should use application(_:open:options:) instead
  • [UPDATE 1] Not yet tested in iOS 10. It will fail because of policies changes in URL scheme handling.
@piotrbernad
piotrbernad / LoadableState.swift
Created September 27, 2017 18:14
LoadableState
public enum LoadableState<ItemType> {
case idle
case loading
case loaded(items: [ItemType])
case contentUnavailable
case refreshing
case error(error: Error)
}
@piotrbernad
piotrbernad / PostsTableViewController.swift
Created September 27, 2017 18:19
EmptyDataSetSource Example
extension PostsTableViewController: DZNEmptyDataSetSource {
func title(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
switch self.state {
case .loading:
return NSAttributedString(string: NSLocalizedString("Loading...", comment: ""))
case .refreshing:
return NSAttributedString(string: NSLocalizedString("Refreshing", comment: ""))
case .error:
return NSAttributedString(string: NSLocalizedString("Error", comment: ""))
default:
@callmeloureiro
callmeloureiro / comoSerChatoNoWhatsapp.js
Last active September 23, 2024 19:29
Como fazer alguém te responder no whatsapp
/*
Hoje iremos MUDAR a vida da pessoa que não te responde no whatsappp...
Que tal enviar mensagens pra ela até obter uma resposta?!
Sensacional não acha?! Mas, somos devs, correto?! Então vamos automatizar esse paranauê!
Para utilizar:
- Abra o web.whatsapp.com;
- Selecione a conversa que você quer;
- Abra o console e cole o código que está no gist;