Skip to content

Instantly share code, notes, and snippets.

View bonifaido's full-sized avatar

Nándor István Krácser bonifaido

View GitHub Profile
@bonifaido
bonifaido / euler16.clj
Created December 5, 2012 10:42
Project Euler - Problem 16
(reduce +
(map #(read-string (str %))
(str (.pow (BigInteger. "2") 1000))))
@bonifaido
bonifaido / disk-speed.zsh
Created November 2, 2012 12:16
Benchmark your HDD or SSD read/write speed
disk-speed() {
tstfile=/tmp/tstfile.$RANDOM
print "Write speed: " $(dd if=/dev/zero bs=1024k of=$tstfile count=1024 2>&1 | awk '/sec/ {print $1 / $5 / 1048576, "MB/sec" }')
purge
print " Read speed: " $(dd if=$tstfile bs=1024k of=/dev/null count=1024 2>&1 | awk '/sec/ {print $1 / $5 / 1048576, "MB/sec" }')
rm $tstfile
}
@bonifaido
bonifaido / diagonal.clj
Created August 5, 2012 09:23
Matrix diagonal
(defn diagonal [m]
(map #(nth (nth m %) %)
(take (count m) (iterate inc 0))))
@bonifaido
bonifaido / gist:3067251
Created July 7, 2012 17:22
git - counting the number of source lines
# Change the regex group to your programming language's extensions
git ls-files | egrep '\.(h|cpp)$' | xargs cat | wc -l
@bonifaido
bonifaido / oql_recipes.js
Last active January 21, 2022 08:00
VisualVM OQL Recipes
// The MIT License (MIT)
//
// Copyright (c) 2015 Nandor Kracser
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@bonifaido
bonifaido / findclass.sh
Created March 22, 2012 14:09
Finds a class in a library of JARs
#!/usr/bin/bash
if [ $# != 2 ]
then
echo usage: findclass [CLASS] [DIR]
exit 1
fi
jars=(`find $2 -name '*.jar'`)
(ns json-bench.core
(:require [cheshire.core :as cheshire])
(:require [clojure.data.json :as json])
(:require [clj-json.core :as clj-json]))
(defn nano-time []
(System/nanoTime))
(defn timed [task]
(let [t-start (nano-time)
@bonifaido
bonifaido / gist:1723274
Created February 2, 2012 12:36
Delete a line from a file with CLI
#!/usr/bin/bash
if [ $# != 2 ] ; then
echo $0 [FILE] [LINENUMBER]
fi
{ rm $1 && awk '{ if (NR != DEL) print }' DEL=$2 > $1; } < $1
@bonifaido
bonifaido / GZipTest.java
Created December 13, 2011 19:04
Correct unzipping with Java
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
public class GZipTest {
public static void main(String[] args) throws IOException {
@bonifaido
bonifaido / is-prime.clj
Created December 6, 2011 09:52
Detects if given integer is a prime?
; Clojure step 1
(defn is-prime? [n]
"Detects if input paramter is a prime."
(if (<= n 3)
true
(let [max (Math/floor (Math/sqrt n))]
(loop [d 2]
(if (zero? (rem n d))
false