Skip to content

Instantly share code, notes, and snippets.

View kana-ph's full-sized avatar

KaNa kana-ph

  • Metro Manila, PH
View GitHub Profile
@kana-ph
kana-ph / groovy.lang
Last active November 6, 2015 07:02
Groovy Language Syntax Highlight for gtksourceview-3.0
<?xml version="1.0" encoding="UTF-8"?>
<language id="groovy" _name="Groovy" version="2.0" _section="Sources">
<metadata>
<property name="mimetypes">text/x-groovy</property>
<property name="globs">*.groovy</property>
<property name="line-comment-start">//</property>
<property name="block-comment-start">/*</property>
<property name="block-comment-end">*/</property>
</metadata>
@kana-ph
kana-ph / ferris-wheel.js
Last active January 29, 2016 15:34
Make images spin!
//javascript:
var r=0;
var x = [0.1, 0.25, 1.6, 300, 300];
var y = [0.05, 0.24, 0.24, 200, 200];
var imgs = document.getElementsByTagName("img");
setInterval(function A() {
for(i=0; i-imgs.length; i++){
@kana-ph
kana-ph / flip.sh
Created February 8, 2016 14:27
Simple flip-coin script using /dev/random
#!/bin/sh
byte=$(head -c 1 /dev/random | cat);
flip=$(printf '%d\n' "'$byte'");
if [ $((flip % 2)) -eq 0 ];
then
echo 'HEADS'
else
echo 'TAILS'
@kana-ph
kana-ph / psql-guide.md
Last active March 15, 2017 10:50
PSQL Install/Setup Guide

Installing postgresql

Fedora, RHEL, CentOS, or similar OS

# yum install postgresql
# yum install postgresql-server

Debian, Ubuntu, Mint, or similar OS

@kana-ph
kana-ph / reset-psql.sh
Created June 6, 2016 09:24
Small script to reset list of postgres databases
#!/bin/sh
for db_name in "$@"
do
echo " * Current DB: $db_name"
psql --host=localhost --user=postgres -c "DROP DATABASE $db_name;"
psql --host=localhost --user=postgres -c "CREATE DATABASE $db_name;"
done
@kana-ph
kana-ph / dnf-fix-fucked-up-gdm.sh
Created June 24, 2016 13:57
Fix lost GNOME desktop on RHEL-based OS
#!/bin/sh
dnf groupinstall -y gnome
systemctl enable gdm
shutdown -r now
@kana-ph
kana-ph / ClosureExperiment.groovy
Created July 22, 2016 07:08
Compares which performs faster in an iteration - method reference vs. invoking method
void square(int i) { i ** 2 }
def rng = new Random()
List numbers = (1..10000000).collect { rng.nextInt(11) }
long start, end
start = System.currentTimeMillis()
numbers.each(this.&square)
@kana-ph
kana-ph / guide-amq_zk.md
Last active February 17, 2023 05:47
ActiveMQ on Zookeeper Setup Guide

Setup Diagram

Image grabbed from ElasticCloudApps.com

Ingredients

  • 3 Linux machines with Installed JDK 1.7+
    • Default setup is 3 Replicas
  • Apache ActiveMQ 5.13.4 (stable)
    • Extract to /opt/activemq/apache-activemq-5.13.4 (We call this ACTIVEMQ_HOME from now on)
  • Apache Zookeeper 3.4.8 (stable)

broker 1

<broker ... brokerName="broker" ...>
    ...
    <persistenceAdapter>
        <replicatedLevelDB
            directory="${activemq.data}/leveldb"
            replicas="3"
            bind="tcp://0.0.0.0:0"
            zkAddress="hostname1:2181,hostname2:2181,hostname3:2181"

UI Class

private Panel displayPanel; // assuming: setup complete

public void showMeals() {
	List<Meal> meals = fetchAllMeals();
	
	for (Meal meal : meals) {
		JButton mealButton = createMealButton(meal);