Skip to content

Instantly share code, notes, and snippets.

View warmwaffles's full-sized avatar
🛠️
Code Wrestling

Matthew Johnston warmwaffles

🛠️
Code Wrestling
View GitHub Profile
#!/bin/bash
rm libs/*.jar
rm -rf tools
echo "========================================"
echo "PULLING GDX LIBRARIES"
echo "========================================"
curl -o libs/gdx.jar "http://libgdx.badlogicgames.com/nightlies/dist/gdx.jar"
curl -o libs/gdx-sources.jar "http://libgdx.badlogicgames.com/nightlies/dist/sources/gdx-sources.jar"
@warmwaffles
warmwaffles / java_ls.sh
Last active December 14, 2015 16:19
Need a quick way to switch java versions in Mac? ~> java_use 1.6
#!/bin/bash
/usr/libexec/java_home -V 2>&1 | grep -E "\d.\d.\d_\d\d" | cut -d , -f 1 | colrm 1 4 | grep -v Home
@warmwaffles
warmwaffles / build.xml
Created March 8, 2013 06:32
libgdx Build file.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Change MYAPPLICATION to yor project name -->
<project basedir="." default="run" name="MYAPPICATION">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<!-- Change MYAPPLICATION to yor project name -->
#!/bin/bash
if [ $# -lt 1 ]
then
echo "Usage : jvm use [1.6|1.7]"
echo " jvm ls"
exit
fi
case $1 in
@warmwaffles
warmwaffles / snippet.rb
Last active March 23, 2017 17:40
A set of useful snippets that I find
# Outputs text with the specified format
#
# @param [String] text what you want to say
# @param [Hash] options
#
# @return [void]
def say text, options={}
color = options[:color] || :white
weight = options[:weight] || :normal
subquery = Article.where(:person_id => 1).select(:id).order{id.desc}.limit(1)
Person.where(:id => 1).select{[id, name, subquery.as('last_article_id')]}.to_sql
=> SELECT "people"."id", "people"."name",
(
SELECT "articles"."id" FROM "articles"
WHERE "articles"."person_id" = 1
ORDER BY "articles"."id" DESC LIMIT 1
) last_article_id
FROM "people" WHERE "people"."id" = 1
public class InputTask implements Runnable {
private final ImmutableBag<Entity> entities;
public InputTask(ImmutableBag<Entity> entities) {
this.entities = entities;
}
@Override
public void run() {
for (int i = 0; i < entities.size(); i++) update(entities.get(i));
}
public class SomeUtilityClass {
private static final ThreadPoolExecutor threads = new ThreadPoolExecutor(
Runtime.getRuntime().availableProcessors(), 10,
10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100, true));
public static void scheduleTask(Runnable runnable) {
threads.execute(runnable);
}
}
package net.warmwaffles;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class Scheduler {
private static Scheduler instance;
private ThreadPoolExecutor executor;
p = lambda do
{:default => <<-DEFAULT_SQL, :mysql => <<-MYSQL}
UPDATE users SET item_count = item_count + 1
WHERE id IN (SELECT user_id FROM buckets WHERE id = NEW.bucket_id)
DEFAULT_SQL
UPDATE users, buckets SET item_count = item_count + 1
WHERE users.id = user_id AND buckets.id = NEW.bucket_id