Skip to content

Instantly share code, notes, and snippets.

@dmurawsky
dmurawsky / index.js
Last active May 22, 2024 19:01
How to make a page full height in Next.js
const FullHeightPage = () => (
<div>
Hello World!
<style global jsx>{`
html,
body,
body > div:first-child,
div#__next,
div#__next > div {
height: 100%;
@yang-wei
yang-wei / destructuring.md
Last active July 4, 2024 16:56
Elm Destructuring (or Pattern Matching) cheatsheet

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
@ihcsim
ihcsim / vim-cheatlist.md
Last active November 19, 2017 17:54
vim cheat list
@alskipp
alskipp / flatMappyMonady.hs
Last active August 29, 2015 14:26
Fear not the flatMapper
-- a function that accepts 2 monad args ‘containing’ number types and multiplies the ‘contents’
mult a b =
a >>= \x ->
b >>= \y -> return (x * y)
mult (Just 2) (Just 3)
-- Just 6
mult Nothing Nothing
-- Nothing
@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:

@bradley219
bradley219 / fix_xcode_plugins
Last active December 11, 2019 06:08
Fix Xcode Plugin UUIDs
#!/bin/bash
UUID=`defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`
echo "UUID=$UUID"
find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add "$UUID"
@natecook1000
natecook1000 / NSScanner+Swift.swift
Created March 3, 2015 20:13
Swift-friendly NSScanner methods
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
//
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension NSScanner {
// MARK: Strings
@algal
algal / groupBy.swift
Last active February 3, 2016 13:47
groupBy
func groupBy<T>(equivalent:(a:T,b:T)->Bool, items:[T]) -> [[T]] {
var lastItem:T? = nil
var groups:[[T]] = []
var currentGroup:[T] = []
for item in items {
if lastItem == nil {
// first item
currentGroup.append(item)
}
else {
#! /bin/bash
# DHC - Hacked to always return a 0 code when successful.
SIM_DEVICES_FOLDER=~/Library/Developer/CoreSimulator/Devices
SIM_RUNTIME_PRFIX=com.apple.CoreSimulator.SimRuntime
function usage () {
echo "simulatorAppFolders (-s <name> | -d <device-type>) [-?] [-i <iOS version>] [-a <app-name>]"
echo "-? show help, and prints simulators currently installed"
@kristopherjohnson
kristopherjohnson / isNilOrEmpty.swift
Last active December 7, 2021 07:03
Swift: determine whether optional String, NSString, or collection is nil or empty
import Foundation
/**
Determine whether Optional collection is nil or an empty collection
:param: collection Optional collection
:returns: true if collection is nil or if it is an empty collection, false otherwise
*/
public func isNilOrEmpty<C: CollectionType>(collection: C?) -> Bool {
switch collection {