Skip to content

Instantly share code, notes, and snippets.

View berkes's full-sized avatar

Bèr Kessels berkes

View GitHub Profile
require "pp"
require "benchmark"
# Yea. Extremely slow and prolly Linux only
def mem_sampler
stat = GC.stat
stat.map do |k,v|
"#{k}\t#{v}"
end.join("\n")
end
@berkes
berkes / log-git-flow-feature
Created April 6, 2016 11:29
Time logging with git flow
set -e
working_dir=$(pwd)
feature=$2
action=$1
now=$(date -u +"%Y-%m-%dT%H:%M:%SZ") # ISO8601
echo "[$now] $working_dir $action $feature" >> ~/.git-flow-feature.log
number=$1
prime=true
#for i in {1.."$number"}
for i in $(seq 2 1 $(($number - 1)))
do
if [ $(($number % $i)) -eq 0 ]
then
prime=false
out="$out \n number $i a factor"
fi
@berkes
berkes / application_helper.rb
Last active October 30, 2015 11:18
Rails helper to render the errors or a form as flash messages.
def flash_errors_for(model)
return unless model.errors.any?
messages = [I18n.t("errors.messages.not_saved",
count: model.errors.size,
resource: model.model_name)]
# Sanitize any errors
messages << model.errors.to_a.map(&:html_safe)
# assign to alert, mark as safe
#!/bin/bash
current=$(dconf read /org/gnome/desktop/input-sources/xkb-options)
swapped="['caps:swapescape']"
capslock="['caps:capslock']"
echo "Current status: $current"
if [ "$current" == "$swapped" ]
then
echo "Making caps and escape WORK NORMALLY"
import robocode.*;
import java.util.Random;
public class Marnick extends Robot {
boolean found = false;
int movingCounter = 72;
public void run() {
while (true) {
if(movingCounter > 0 || found) {
movingCounter--;
/**
* Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
package sample;
package sample;
import java.util.Random;
import robocode.Robot;
import robocode.Rules;
import robocode.ScannedRobotEvent;
public class Klaas extends Robot {
private int scannedX;
package EB9000;
import robocode.*;
//import java.awt.Color;
// API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html
/**
* Evilbot9000 - a robot by (your name here)
*/
public class Evilbot9000 extends Robot
@berkes
berkes / ruby-build.log
Created April 12, 2015 14:30
Ruby build error log
/tmp/ruby-build.20150412141408.30731 /opt/rbenv
HTTP/1.1 200 OK
Content-Type: binary/octet-stream
Content-Length: 503012
Connection: keep-alive
Date: Tue, 10 Feb 2015 13:45:53 GMT
Last-Modified: Fri, 23 May 2014 08:48:21 GMT
ETag: "5fe00cda18ca5daeb43762b80c38e06e"
Accept-Ranges: bytes
Server: AmazonS3