Skip to content

Instantly share code, notes, and snippets.

@remysucre
remysucre / gb.cgi
Created January 19, 2024 00:17
CGI script in Python for a guestbook
#!/usr/bin/env python
import cgi
import sqlite3
# Create or connect to the SQLite database
conn = sqlite3.connect('gb.db')
cursor = conn.cursor()
# Create a table to store guestbook entries if it doesn't exist
@remysucre
remysucre / guestbook.cgi
Created January 18, 2024 23:55
Simple CGI script for a guestbook
#!/bin/ksh
# Function to create the SQLite database and table if they don't exist
create_database() {
if [ ! -f guestbook.db ]; then
sqlite3 guestbook.db 'CREATE TABLE entries (id INTEGER PRIMARY KEY AUTOINCREMENT, message TEXT)'
fi
}
# Function to fetch and display guestbook entries
@remysucre
remysucre / eq.sql
Last active July 27, 2023 03:50
Check if two SQL tables are the same
CREATE TABLE t1 (x INTEGER);
CREATE TABLE t2 (x INTEGER);
INSERT INTO t1 VALUES (1), (1), (2), (3);
INSERT INTO t2 VALUES (2), (1), (3), (2);
-- If t1=t2 (meaning they are the same bag/multiset), then the following should return nothing.
-- Sanity check: do they contain the same *set* of elements (ignoring duplicates)?
@remysucre
remysucre / main.rs
Last active February 23, 2022 18:15
merge-only rules in egg
use egg::*;
/// A [`Condition`] that checks if a pattern is already in the egraph.
pub struct ConditionExists<L> {
p: Pattern<L>,
}
impl<L: Language> ConditionExists<L> {
/// Create a new [`ConditionExists`] condition given a pattern.
pub fn new(p: Pattern<L>) -> Self {

Entropy

Entropy can be understood as the minimum amount of data needed to be transmitted in order to communicate a piece of information. Concretely, this is the average number of bits needed to encode a message. For example, imagine a spaceship sends a status code every minute to indicate if it has found any alien civilization. The code is any letter from the English alphabet, with $A$ meaning "nothing new", and some other letter describing the alien. For example $F$ means the alien is friendly, and $B$ means the alien is blue, etc. For simplicity assume every code is only 1-letter long. Then we can simply encode this status

âPNG

IHDR ~¶QÏ}IDATx⁄Ì¡Äê˛ØÓ
ĨèÓ˘tjIENDÆB`Ç
@remysucre
remysucre / index.html
Last active June 27, 2018 18:42
move
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Examples of D3 transitions</title>
<style>
svg {
border: 1px solid black;
}
fieldset {
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Examples of D3 transitions</title>
<style>
svg {
border: 1px solid black;
}
fieldset {
@remysucre
remysucre / fp.java
Created April 10, 2018 17:17
false positives
/Users/rem/metalift/txl/qbs/allbench//GuidanceService.java
{
java.util.Set<wilos.model.spem2.activity.Activity> tmp = new java.util.HashSet<wilos.model.spem2.activity.Activity>();
this.guidanceDao.getSessionFactory().getCurrentSession().saveOrUpdate(_guidance);
java.util.Iterator extfor$iter = _guidance.getActivities().iterator();
while (extfor$iter.hasNext())
{
wilos.model.spem2.activity.Activity act = (wilos.model.spem2.activity.Activity) extfor$iter.next();
tmp.add(act);
}
@remysucre
remysucre / fn.java
Last active April 10, 2018 17:18
false negatives
/Users/rem/metalift/txl/qbs/allbench//WorkProductSExpTableBean.java
{
int numberOfFinishedActivity = 0;
wilos.model.misc.project.Project project = this.projectService.getProject(((java.lang.String) wilos.presentation.web.utils.WebSessionService.getAttribute(wilos.presentation.web.utils.WebSessionService.PROJECT_ID)));
if (this.concreteActivityService.getConcreteActivitiesFromProject(project).size() != 0)
{
labeled_1: {
java.util.Iterator extfor$iter = this.concreteActivityService.getConcreteActivitiesFromProject(project).iterator();
while (extfor$iter.hasNext())
{