Skip to content

Instantly share code, notes, and snippets.

View cristobal's full-sized avatar
💭
¯\_(ツ)_/¯

Cristobal Dabed cristobal

💭
¯\_(ツ)_/¯
View GitHub Profile
public class JavaTutorial10 {
public static void main(String[] args) {
String value = "abc";
// 1. Strings are not null terminated in java
System.out.println(value.toCharArray());
System.out.println("");
@cristobal
cristobal / shuffle.lua
Created March 25, 2014 22:00
Lua implementation of Fisher-Yates Shuffle "inside-out"
-- Remember to seed outside the function i.e. at top of your script
-- especially on OSX otherwise you will get the same permutations.
-- math.randomseed(os.time())
-- More info http://lua-users.org/wiki/MathLibraryTutorial
function random(min, max)
if (max == null) then
max = min
min = 0
end
@cristobal
cristobal / Intellij.desktop
Created October 14, 2013 12:50
Intellij Desktop Entry for Ubuntu
[Desktop Entry]
Name=IntelliJ
Comment=The Best Java and Polyglot IDE
Exec=/home/cristobal/Applications/idea-<version>/bin/idea.sh
Icon=/home/cristobal/Applications/idea-<version>/bin/idea.png
Terminal=false
StartupNotify=true
Type=Application
Categories=Development;IDE;
@cristobal
cristobal / CustomContainer.java
Last active December 24, 2015 12:19
Custom Wicket Event Message Example
class CustomContainer extends WebMarkupContainer {
public CustomContainer(String id) {
super(id);
}
@override
public void onBeforeRender() {
// Some form do forward message passing for
// All Pages/Componets implements IEventSource
# Start numbering at 1
set -g base-index 1
# Allows for faster key repetition
set -s escape-time 0
# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
setw -g aggressive-resize on
@cristobal
cristobal / zepto.visible.js
Created May 2, 2013 15:44
Zepto Visible filter.
$.fn.visible = function() {
return this.map(function () {
if (!_.contains(['none', 'hidden'], $(this).css('display'))) {
return this;
}
})
};
@cristobal
cristobal / ucs2_encode.lua
Last active December 16, 2015 17:39
UCS2 encode a string for sending via AT modem using `%04x` hex format.
local function ucs2_encode(str)
local cc = {}
local bv = {1, 2, 4, 8, 16, 32, 64, 128}
local fmt = "%04x"
-- bit_set taken from http://ricilake.blogspot.no/2007/10/iterating-bits-in-lua.html
local function bit_set(x, p)
return x % (p + p) >= p
end
function bin2hex (str)
local val = ""
for i = 1, str:len() do
char = string.byte(str:sub(i, i))
val = string.format("%s%02X%s", val, char, "")
end
return val
end
@cristobal
cristobal / strpos.lua
Created April 9, 2013 16:01
Lua variant for the php strpos function
function strpos (haystack, needle, offset)
local pattern = string.format("(%s)", needle)
local i = string.find (haystack, pattern, (offset or 0))
return (i ~= nil and i or false)
end
@cristobal
cristobal / date.lua
Last active December 15, 2015 11:59
Port of php.js date to lua http://phpjs.org/functions/date/
function date (format, timestamp)
-- @credits https://raw.github.com/kvz/phpjs/master/functions/datetime/date.js
local c = {}
local f = nil
local formatPattern = "%a"
local pad = function (v, s)
v = tostring(v)
if string.len(v) < s then