Skip to content

Instantly share code, notes, and snippets.

Avatar
🏔️

ixaxaar ixaxaar

🏔️
View GitHub Profile
@eligrey
eligrey / object-watch.js
Created Apr 30, 2010
object.watch polyfill in ES5
View object-watch.js
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
@sixtenbe
sixtenbe / analytic_wfm.py
Last active Oct 1, 2021 — forked from endolith/peakdet.m
Peak detection in Python
View analytic_wfm.py
#!/usr/bin/python2
# Copyright (C) 2016 Sixten Bergman
# License WTFPL
#
# This program is free software. It comes without any warranty, to the extent
# permitted by applicable law.
# You can redistribute it and/or modify it under the terms of the Do What The
# Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See
@tixxit
tixxit / EditDistance.scala
Created Sep 28, 2011
Short Levenshtein distance implementation in Scala
View EditDistance.scala
package net.tixxit.levenshtein
import scala.math.min
object EditDistance {
def editDist[A](a: Iterable[A], b: Iterable[A]) =
((0 to b.size).toList /: a)((prev, x) =>
(prev zip prev.tail zip b).scanLeft(prev.head + 1) {
case (h, ((d, v), y)) => min(min(h + 1, v + 1), d + (if (x == y) 0 else 1))
}) last
@copumpkin
copumpkin / Prime.agda
Last active May 17, 2020
There are infinite primes
View Prime.agda
module Prime where
open import Coinduction
open import Data.Empty
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Divisibility
open import Data.Fin hiding (pred; _+_; _<_; _≤_; compare)
open import Data.Fin.Props hiding (_≟_)
@rednaxelafx
rednaxelafx / Notes.md
Created Nov 17, 2011
java.lang.InternalError: a fault occurred in a recent unsafe memory access operation in compiled Java code
View Notes.md

Error message:

2011-11-17 09:32:51,715 [ajp-0.0.0.0-8009-3] ERROR com.alibaba.citrus.webx.impl.WebxRootControllerImpl - Error occurred while process request /
java.lang.InternalError: a fault occurred in a recent unsafe memory access operation in compiled Java code
        at java.nio.Bits.swap(Bits.java:27) ~[na:1.6.0_17]
        at java.nio.Bits.swap(Bits.java:37) ~[na:1.6.0_17]
        at java.nio.DirectByteBuffer.getInt(DirectByteBuffer.java:614) ~[na:1.6.0_17]
        at java.nio.DirectByteBuffer.getInt(DirectByteBuffer.java:624) ~[na:1.6.0_17]
        at com.taobao.common.nmap.Nmap.next2(Nmap.java:135) ~[common-nbeanutils-1.2.0.jar:na]
View AgdaBasics.agda
module AgdaBasics where
apply : (A : Set)(B : A Set) ((x : A) B x) (a : A) B a
apply A B f a = f a
_∘_ : {A : Set}{B : A Set}{C : (x : A) B x Set}
(f : {x : A}(y : B x) C x y)(g : (x : A) B x)
(x : A) C x (g x)
(f ∘ g) x = f (g x)
@paradigmatic
paradigmatic / FASTA.scala
Created Aug 23, 2012
FASTA parser in Scala
View FASTA.scala
import scala.util.parsing.combinator._
object FASTA {
case class Entry( description: String, sequence: String )
def fromFile( fn: String ): List[Entry] = {
val lines = io.Source.fromFile(fn).getLines.mkString("\n")
fromString( lines )
}
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active Nov 27, 2021
Useful PostgreSQL Queries and Commands
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@ryandotsmith
ryandotsmith / agg.sql
Created Jan 23, 2013
Postgres array concatenation aggregate function.
View agg.sql
CREATE AGGREGATE array_accum (anyarray)
(
sfunc = array_cat,
stype = anyarray,
initcond = '{}'
);
@MLnick
MLnick / StreamingHLL.scala
Last active Dec 7, 2019
Spark Streaming meets Algebird's HyperLogLog Monoid
View StreamingHLL.scala
import spark.streaming.StreamingContext._
import spark.streaming.{Seconds, StreamingContext}
import spark.SparkContext._
import spark.storage.StorageLevel
import spark.streaming.examples.twitter.TwitterInputDStream
import com.twitter.algebird.HyperLogLog._
import com.twitter.algebird._
/**
* Example of using HyperLogLog monoid from Twitter's Algebird together with Spark Streaming's