Skip to content

Instantly share code, notes, and snippets.

@kajic
kajic / statements.txt
Last active January 11, 2023 08:35
Texas death row inmate last statements
Name: Charlie Brooks, Jr. (12/07/1982)
Statement:
Statement to the Media: I, at this very moment, have absolutely no fear of what may happen to this body. My fear is for Allah, God only, who has at this moment the only power to determine if I should live or die... As a devout Muslim, I am taught and believe that this material life is only for the express purpose of preparing oneself for the real life that is to come... Since becoming Muslim, I have tried to live as Allah wanted me to live.
Spoken:
Yes, I do.
I love you.
@kajic
kajic / copilot_test.js
Last active November 11, 2022 07:52
I just tried GitHub Copilot for the first time. This is the file that we created together. I would love to see your interactions.
// Meeting Github Copilot for the first time.
function calculateDaysBetweenDates(date1, date2) {
const diff = Math.abs(date2 - date1); // Difference in milliseconds
return Math.ceil(diff / (1000 * 60 * 60 * 24)); // Days
}
console.log(calculateDaysBetweenDates(new Date('July 12, 2016'), new Date('July 22, 2016')));
// Wow! This was a lot of work. We can do better. Let's use a library.
.css-selector {
    background: linear-gradient(0deg, #24662f, #000000, #24662f);
    background-size: 600% 600%;
    -webkit-animation: AnimationName 16s ease infinite;
    -moz-animation: AnimationName 16s ease infinite;
    -o-animation: AnimationName 16s ease infinite;
    animation: AnimationName 16s ease infinite;
}
@-webkit-keyframes AnimationName {
    0%{background-position:51% 0%}
@kajic
kajic / twofishes
Created March 11, 2014 16:37
init.d script for twofishes, assumes you have a twofishes user with the binary and data in /home/twofishes/opt/twofishes
#!/bin/sh
JAVA=/usr/bin/java
JAR=/home/twofishes/opt/twofishes/server-assembly-0.81.9.jar
DATA=/home/twofishes/opt/twofishes/data/
OPTS="-Xmx4096m -jar $JAR --hfile_basepath $DATA --preload 1 --warmup 1"
NAME=twofishes
DESC=twofishes
@kajic
kajic / hash_of_array.rb
Last active December 31, 2015 11:39
HashOfArray keeps track of the combined order in which elements are appended to its arrays.
# HashOfArray keeps track of the combined order in which elements are appended to its
# arrays.
# HashOfArray.items returns all items appended to the arrays, in the order they were
# appended.
#
# Example:
#
# h = HashOfArray.new
#
# h[:a] << 1
@kajic
kajic / sentence_join.rb
Created September 26, 2013 18:35
Joins ['Uhura', 'Spock', 'Troi', 'Kirk', 'Worf'] into the string 'Uhura, Spock, Troi and 2 others'.
# Public: Join lists into sentence-like strings of the form a, b, c and 2 others.
#
# options - Options hash.
# :max - The maximum number of items to include in the result
# (default: 3).
# :delimiter - Delimiter between items (default: ', ').
# :last_delimiter - Delimiter between the two last items (default: ' and ').
# :others_formatter - Block called to format the '3 others' suffix
# (default: pluralize(count, 'other'))
# &formatter - Block called to format each item (default: item.to_s).
@kajic
kajic / cipher.rb
Created May 31, 2013 16:11
Blowfish encryption and decryption of strings
require 'openssl'
require 'base64'
module Cipher
def self.encrypt(key, data)
data += 'A' # Add 'A' suffix to support empty data
cipher(:encrypt, key, data)
end
def self.decrypt(key, text)
@kajic
kajic / kahan.rb
Created April 25, 2013 13:32
Kahan sum
# Reduces numerical error when adding a sequence of floats.
# http://en.wikipedia.org/wiki/Kahan_summation_algorithm
#
# Examples:
#
# Sums all given arguments:
# KahanSum.new([3.14159265358979323846 , 2.71828182845904523536], 1.41421356237309504880)
# => #<KahanSum:0x007fd218984120 @sum=7.274088044421934, @c=2.220446049250313e-16>
#
# Incremental summation:
@kajic
kajic / es.sh
Last active October 1, 2015 07:57 — forked from aaronshaf/es.sh
Install ElasticSearch on Ubuntu 10.04/11.04
cd ~
sudo apt-get update
sudo apt-get install curl python-software-properties -y
sudo apt-get install openjdk-6-jre-headless
curl -L http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.2.tar.gz | tar -xz
sudo mv elasticsearch-* /usr/local/share/elasticsearch
curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz
sudo mv *servicewrapper*/service /usr/local/share/elasticsearch/bin/
rm -Rf *servicewrapper*