Skip to content

Instantly share code, notes, and snippets.

@mahemoff
mahemoff / ask-wikipedia.rb
Last active August 29, 2015 13:56 — forked from emad-elsaid/ask-wikipedia.rb
Refactor processing, make script standalone with initial env, add command-line argument
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
language = 'en'
article = ARGV[0] ||
begin
print 'What do you need to know? : '
URI::encode gets.chomp
@smat
smat / SemaphoreFilter.java
Created February 25, 2015 09:03
Semaphore filter
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.Semaphore;
// This sample will guide you through elements of the F# language.
//
// *******************************************************************************************************
// To execute the code in F# Interactive, highlight a section of code and press Alt-Enter or right-click
// and select "Execute in Interactive". You can open the F# Interactive Window from the "View" menu.
// *******************************************************************************************************
//
// For more about F#, see:
// http://fsharp.org
//
@gnab
gnab / whenCacheInSync.js
Last active December 18, 2015 07:39
Reload until application cache is in sync (noupdate). If you don't reload after app cache is updated, you'll still be using old html/css/js until the next time you reload. Should be called initially with a callback that loads your application like you normally would.
function whenCacheInSync(callback) {
// 1. Checking
var onChecking = function () {
window.applicationCache.removeEventListener('checking', onChecking);
window.applicationCache.addEventListener('noupdate', onNoUpdate);
window.applicationCache.addEventListener('downloading', onDownloading);
};
// 1A. No updates, load app
@toricls
toricls / kibana.sh
Last active February 26, 2016 23:05
Kibana 4 Init script for Amazon Linux
#!/bin/sh
### BEGIN INIT INFO
# Provides: kibana
# Required-Start: $local_fs $remote_fs $network
# Should-Start: $time
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Kibana 4

Let's Encrypt with nginx + auto renewal

Let's Encrypt is a new, free, automated, and open Certificate Authority.

Find out more out Let's Encrypt, and how you can use in the Let's Encrypt documentation.

This file will guide you through the minimum things you need to set up Let's Encrypt on your nginx webserver.

@smat
smat / Luke1.kt
Last active December 9, 2016 09:21
Julekalender 2016
import java.lang.Math.floor
import java.lang.Math.log10
import java.util.stream.Stream
fun main(args: Array<String>) {
Stream.iterate(6, { it + 10 } )
.filter { swapFirstAndLastDigit(it) == 4 * it }
.findFirst()
.map { println(it) }
}
@int3
int3 / gist:4027626
Created November 6, 2012 21:17
Chained comparisons using sweet.js
macro $if {
case ($x ...) => { if (relCar($x ...)) }
}
macro $while {
case ($x ...) => { while (relCar($x ...)) }
}
// naive form:
/*
@torgeir
torgeir / clipboard-utils.clj
Last active March 1, 2017 07:49 — forked from Folcon/clipboard-utils.clj
Just a quick clipboard slip/slurp I put together because I didn't find anything similar, don't know if it's useful for anyone but found it invaluable when getting large strings being returned from the repl and sticking the result in an editor for more car
(defn get-clipboard []
(.getSystemClipboard (java.awt.Toolkit/getDefaultToolkit)))
(defn slurp-clipboard []
(if-let [contents (.getContents (get-clipboard) nil)]
(.getTransferData contents java.awt.datatransfer.DataFlavor/stringFlavor)))
(defn spit-clipboard [text]
(.setContents (get-clipboard) (java.awt.datatransfer.StringSelection. text) nil))
@jstepien
jstepien / reduce-and-gc.clj
Last active March 6, 2017 11:21
reduce-and-gc.clj
;; Let's experiment with Clojure 1.8.0 running with a relatively small heap
;; of 10MB. To avoid any extra dependencies, we'll start it as follows:
;;
;; java -Xmx10m -jar clojure-1.8.0.jar
;;
;; Copy following expressions into your REPL one by one.
;;
;; Let's take a small number, for instance one million.
(def small-num (* 1000 1000))