Skip to content

Instantly share code, notes, and snippets.

@laurilehmijoki
laurilehmijoki / keyboardHeightObservable.swift
Last active November 15, 2022 13:00
RxSwift Observable on iOS keyboard height
import RxSwift // Version 3.2.0
import RxCocoa // Version 3.2.0
func keyboardHeight() -> Observable<CGFloat> {
return Observable
.from([
NotificationCenter.default.rx.notification(NSNotification.Name.UIKeyboardWillShow)
.map { notification -> CGFloat in
(notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.height ?? 0
},
@laurilehmijoki
laurilehmijoki / use-system-clipboard-with-vim.md
Last active August 29, 2015 13:56
Use system clipboard with VIM

Problem

The "integrate VIM with the system clipboard" feature does not work on OS X 10.8+ and VIM 7.3.

Solution

  • Compile VIM from source
  • Enable the system-clipboard integartion in .vimrc

Compile VIM

@laurilehmijoki
laurilehmijoki / maxProductOfFiveConsecutiveInts.java
Last active December 24, 2015 18:09
Find the maximum product of five consecutive integers.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;
import java.util.stream.Stream;
import static java.lang.Integer.parseInt;
import static java.util.Comparator.naturalOrder;
public class Test {
@laurilehmijoki
laurilehmijoki / maxProductOfFiveConsecutiveInts.clj
Created October 4, 2013 17:19
Find the maximum product of five consecutive integers.
(def numbers-in-string (str "37900490610897696126265185408732594047834333441947"
"01850393807417064181700348379116686008018966949867"
"75587222482716536850061657037580780205386629145841"
"06964490601037178417735301109842904952970798120105"
"47016802197685547844962006690576894353336688823830"
"22913337214734911490555218134123051689058329294117"
"83011983450277211542535458190375258738804563705619"
"55277740874464155295278944953199015261800156422805"
"72771774460964310684699893055144451845092626359982"
"79063901081322647763278370447051079759349248247518"))
@laurilehmijoki
laurilehmijoki / maxProductOfFiveConsecutiveInts.hs
Last active December 24, 2015 16:38
Find the maximum product of five consecutive integers.
import Data.Char(digitToInt)
nums = "37900490610897696126265185408732594047834333441947018503938074170641817003483791166860080189669498677558722248271653685006165703758078020538662914584106964490601037178417735301109842904952970798120105470168021976855478449620066905768943533366888238302291333721473491149055521813412305168905832929411783011983450277211542535458190375258738804563705619552777408744641552952789449531990152618001564228057277177446096431068469989305514445184509262635998279063901081322647763278370447051079759349248247518"
partition _ [] = []
partition n xs = [take n xs] ++ (partition n $ drop n xs)
partitioned = map (map digitToInt) $ partition 5 nums
maxProduct = maximum $ map (foldl1 (*)) partitioned
@laurilehmijoki
laurilehmijoki / gist:4492781
Created January 9, 2013 12:28
OS X key repeat
# For inspiration, see http://mths.be/osx
# Set a shorter Delay until key repeat (requires OS restart to take effect)
defaults write NSGlobalDomain InitialKeyRepeat -int 12
# Set a blazingly fast keyboard repeat rate (requires OS restart to take effect)
defaults write NSGlobalDomain KeyRepeat -int 0.02
defaults write com.apple.finder AppleShowAllFiles TRUE
# Disable the “Are you sure you want to open this application?” dialog
@laurilehmijoki
laurilehmijoki / StaticFileServlet.scala
Last active December 12, 2018 04:59
Static file servlet with Scalatra
package coolcode
import java.io.File
import java.util.Properties
import org.scalatra.ScalatraServlet
class StaticFileServlet extends ScalatraServlet {
get("/*") {
val resourcePath = getResourcePath
#!/bin/bash -x
if [ -r /usr/share/java-utils/java-functions ]; then
. /usr/share/java-utils/java-functions
else
echo "Can't read Java functions library, aborting"
exit 1
fi
# Get the tomcat config (use this for environment specific settings)