Skip to content

Instantly share code, notes, and snippets.

@heyimalex
heyimalex / sqlmap.go
Last active April 6, 2024 14:25
Functions for querying directly into map[string]interface{}
// Package sqlmap provides functions for querying directly into
// map[string]interface{}.
//
// In developing really simple api endpoints, I found the boilerplate needed
// to take the results of a database query and output them as JSON to be
// really fucking annoying; make a custom struct, scan into that struct, if
// there are multiple rows do the whole rows.Next() song and dance, and if
// anything changes update the three spots each column of the result is now
// dependent on. Even when using libraries like sqlx, there's still a lot of
// extraneous code that needs to be written.
@mindplay-dk
mindplay-dk / session-life-cycle.md
Last active March 28, 2024 19:52
Complete overview of the PHP SessionHandler life-cycle

This page provides a full overview of PHP's SessionHandler life-cycle - this was generated by a set of test-scripts, in order to provide an exact overview of when and what you can expect will be called in your custom SessionHandler implementation.

Each example is a separate script being run by a client with cookies enabled.

To the left, you can see the function being called in your script, and to the right, you can see the resulting calls being made to a custom session-handler registed using session_set_save_handler().

@jedp
jedp / gist:3005816
Created June 27, 2012 18:18
postMessage() security review checklist

Security-Reviewing Uses of postMessage()

The postMessage() API is an HTML5 extension that permits string message-passing between frames that don't share the same origin. It is available in all modern browsers. It is not supported in IE6 and IE7.

postMessage is generally considered very secure as long as the programmer is careful to check the origin and source of an arriving

@mattkohl
mattkohl / .block
Last active March 26, 2024 18:26
Force-Directed Graph with Multiple Labelled Edges between Nodes
license: gpl-3.0
@naaman
naaman / gist:1053217
Created June 29, 2011 05:33
Hot Swapping With Maven, Jetty and IntelliJ

Hot Swapping With Maven, Jetty and IntelliJ

Based on Configuring Jetty, Maven, and Eclipse together with Hot Swap

I've always been a bit jealous when it comes to the Play! framework and the great dev mode they have for hot swapping classes at runtime. Jetty has a configuration setting, scanIntervalSeconds, that mimics this when working with a more traditional WAR, but does so by looking for changes to a file and restarting the server.

Fortunately, Jetty also provides the ability to rapidly test code with hot swapping. No more server restarts. The trick to getting hot swapping to work is to attach a remote debugger to your Jetty process. The following instructions outline how to do this in IntelliJ (tested with IDEA 10.5 CE).

Modify your jetty-maven-plugin to ignore the scan interval

  1. Open your pom and locate the plugins section
@bennadel
bennadel / index.htm
Created August 18, 2022 12:13
Rendering Wrapped Text To A Canvas In JavaScript
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>
Rendering Wrapped Text To A Canvas In JavaScript
</title>
<link rel="stylesheet" type="text/css" href="./main.css" />
</head>
<body>
@ndarville
ndarville / business-models.md
Last active January 13, 2024 17:27
Business models based on the compiled list at http://news.ycombinator.com/item?id=4924647. I find the link very hard to browse, so I made a simple version in Markdown instead.

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
@janakiramm
janakiramm / Oscar_bot.py
Created July 20, 2023 13:34
Implementing RAG with OpenAI
import openai
import tiktoken
from scipy import spatial
import pandas as pd
df=pd.read_csv('./data/oscars.csv')
print(df.head())
df=df.loc[df['year_ceremony'] == 2023]
df=df.dropna(subset=['film'])
@erkie
erkie / background.html
Created May 19, 2012 09:43
Save parts of screen using Chrome extension
<script>
var Constants = {
saveURL: 'http://random/birthday/saveimage.php',
w: 500,
h: 500,
x: 200,
y: 200
};
@tkrs
tkrs / parser.go.y
Created February 13, 2018 05:31
goyacc tutorial
%{
package main
import (
"text/scanner"
"strconv"
"strings"
"fmt"
)
type Expression interface{}
type ParenExpr struct {