Skip to content

Instantly share code, notes, and snippets.

View chochos's full-sized avatar
💩
(╯°□°)╯︵ ┻━┻

Enrique Zamudio chochos

💩
(╯°□°)╯︵ ┻━┻
View GitHub Profile
@chochos
chochos / Example.java
Created September 28, 2022 16:03
Piped streams
import java.io.*;
public class Example {
private InputStream reportProducer(int lines) throws IOException {
var pin = new PipedInputStream();
var pout = new PipedOutputStream(pin);
var out = new PrintStream(pout);
Runnable generator = () -> {
for (int i = 0; i < lines; i++) {
@chochos
chochos / PlainThreads.java
Created October 17, 2018 15:53
Threads & Thread Pool Executors
public class PlainThreads {
public static void main(String... args) {
for (int i = 0; i < 100; i++) {
new Thread(new Task1()).start();
}
}
}
@chochos
chochos / GameOfLife.ceylon
Last active November 29, 2020 08:37
The Game of Life, implemented in Ceylon, for display in the Ceylon web IDE. You can run this on https://trybeta-ceylon.rhcloud.com/
class Cell(index) {
doc "The index of the Cell inside its Matrix."
shared Integer index;
doc "The current state of the Cell."
shared variable Boolean state = false;
doc "The next state of the Cell."
variable Boolean ns = false;
shared Boolean nextState { return ns; }
assign nextState {
@chochos
chochos / table_function_no_errors.sql
Created July 22, 2019 18:05
Version 2 of using a table function instead of a view, this time no errors are thrown anywhere.
CREATE TABLE foo(
some_id SERIAL PRIMARY KEY,
another INT,
stuff VARCHAR(20)
);
CREATE OR REPLACE FUNCTION insert_crap_into_foo() RETURNS INTERVAL AS
$$
DECLARE
counter INT := 0;
@chochos
chochos / table_function_instead_of_view.sql
Created July 22, 2019 17:39
Using a table function instead of a view.
CREATE TABLE foo(
some_id SERIAL PRIMARY KEY,
another INT,
stuff VARCHAR(20)
);
CREATE OR REPLACE FUNCTION insert_crap_into_foo() RETURNS INTERVAL AS
$$
DECLARE
counter INT := 0;
@chochos
chochos / issue_with_postgres_views.sql
Created July 22, 2019 16:59
Cannot alter a column used in a view, need to drop the view first.
CREATE TABLE foo(
some_id SERIAL PRIMARY KEY,
another INT,
stuff VARCHAR(20)
);
CREATE OR REPLACE FUNCTION insert_crap_into_foo() RETURNS INTERVAL AS
$$
DECLARE
counter INT := 0;
@chochos
chochos / root types.ceylon
Created June 14, 2017 14:35
Definition of the root types in Ceylon
//Anything can only have two subtypes: Object and Null
shared abstract class Anything() of Object | Null {}
shared class Object() extends Anything() {}
//Null can only have one instance, called null
shared abstract class Null()
of null
extends Anything() {}
@chochos
chochos / module.ceylon
Created June 27, 2016 14:55
Using npm from Ceylon
module test "0.1" {
import "npm:uuid" "2.0.2";
}
@chochos
chochos / BraindeadServer.groovy
Created March 25, 2016 19:32
Braindead HTTP server
class BraindeadServer {
int port
private ServerSocket server
String response
void start() {
server = new ServerSocket(port)
byte[] buf = new byte[128]
new Thread({->
@chochos
chochos / gist:7603754
Created November 22, 2013 17:29
Inner class bug in Groovy
class Parent {
String name
}
class External extends Parent {
String outer
Internal inner(String p) {
new Internal(inner:p)
}
class Internal {
String inner