Skip to content

Instantly share code, notes, and snippets.

@vorburger
vorburger / CopyResourcesFromClassPathToFilesystemDirectory.java
Created July 3, 2011 22:29
Copy resources from Classpath into a temporary directory
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
@mbostock
mbostock / .block
Last active July 8, 2023 20:00
SVG foreignObject Example
license: gpl-3.0
@douglasjarquin
douglasjarquin / gist:2208690
Created March 26, 2012 18:58
Amazon RDS Performance Tuning Settings
rds-modify-db-parameter-group {param-group-name} \
--parameters="name=character_set_server, value=utf8, method=pending-reboot" \
--parameters="name=collation_server, value=utf8_general_ci, method=pending-reboot" \
--parameters="name=tmp_table_size, value={DBInstanceClassMemory/16}, method=pending-reboot" \
--parameters="name=max_heap_table_size, value={DBInstanceClassMemory/16}, method=pending-reboot" \
--parameters="name=query_cache_type, value=1, method=pending-reboot" \
--parameters="name=query_cache_size, value=131072, method=pending-reboot" \
--parameters="name=table_open_cache, value=2500, method=pending-reboot" \
--parameters="name=join_buffer_size, value={DBInstanceClassMemory/64}, method=pending-reboot" \
--parameters="name=thread_cache_size, value={DBInstanceClassMemory/12582880}, method=pending-reboot" \
@adactio
adactio / placeholderFromDatalist.js
Created August 12, 2012 15:54
Generate a placeholder attribute from the datalist associated with that input.
(function(win,doc) {
if (doc.querySelectorAll) {
var inputs = doc.querySelectorAll('input[list]'),
total = inputs.length;
for (var i=0; i<total; i++) {
var input = inputs[i],
id = input.getAttribute('list'),
list = doc.getElementById(id),
options = list.getElementsByTagName('option'),
amount = options.length,
@drawcode
drawcode / mysql_drop_index_if_exists.sql
Last active February 29, 2020 19:01
MYSQL Drop Index If Exists
DELIMITER $$
DROP PROCEDURE IF EXISTS drop_index_if_exists $$
CREATE PROCEDURE drop_index_if_exists(in theTable varchar(128), in theIndexName varchar(128) )
BEGIN
IF((SELECT COUNT(*) AS index_exists FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE() and table_name =
theTable AND index_name = theIndexName) > 0) THEN
SET @s = CONCAT('DROP INDEX `' , theIndexName , '` ON `' , theTable, '`');
PREPARE stmt FROM @s;
EXECUTE stmt;
@matteocedroni
matteocedroni / SecurityChecker.java
Last active September 20, 2023 00:47
Programmatically check Spring Security expressions
import org.apache.log4j.Logger;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.security.access.expression.ExpressionUtils;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
import org.springframework.security.util.SimpleMethodInvocation;
import java.lang.reflect.Method;
@bittner
bittner / django-csrftoken-login-demo.bash
Last active August 15, 2022 23:45
Login and perform actions in a Django site (now with less security issues)
# source this code in a Bash shell ($ . django-csrftoken-login-demo.bash),
# and run with a DB name as parameter (e.g. $ django-csrftoken-login-demo demo)
django-csrftoken-login-demo() {
# -- CHANGE THESE VALUES TO MATCH YOUR ACCOUNT --
local HOSTING_USERID=9988
local HOSTING_PANEL_USER='[email protected]'
local HOSTING_PANEL_PASS='my secret login password'
local HOSTING_DB_PREFIX='username_'
local DB_NAME=$HOSTING_DB_PREFIX$1
@amokan
amokan / README.md
Last active December 9, 2019 19:11
Expert Sleepers Disting simple example of audio processing

Some really basic examples of audio processing code for the Expert Sleepers Disting eurorack module.

You can find the base repo for a blank audio passthrough project at https://github.com/expertsleepersltd/disting

You will need to have a 'PICKit 3' USB programmer and the MPLAB IDE (free Microchip dev tools) installed. I grabbed my PICKit from Mouser a while ago and it should be easy to find, wherever you are.

If you want to reflash the stock firmware, you can download that from Expert Sleepers here - http://www.expert-sleepers.co.uk/downloads/firmware/disting_firmware_1_0.zip

Note that the stock firmware is already compiled, so you'll just want to flash it using the 'mplab_ipe' tool.

@tchapin
tchapin / gist:9d5df61bde4ac5cc33fe
Last active August 29, 2015 14:06
Dojo Dialog positioning example
/**
* Created by tchapin on 9/23/2014.
*/
require([
"dojo/aspect",
"dojo/dom-style",
"dojo/on",
"dojo/_base/declare",
"dojo/_base/lang",
"dijit/form/Button",
@kenwdelong
kenwdelong / JGroupsHibernateAWS.md
Created July 13, 2015 18:25
Using JGroups for Hibernate Second-Level Cache in AWS EC2

Configuring a Hibernate second-level cache in AWS is something of a challenge, as the EhCache multicast discovery mechanism doesn't work there. JGroups is another option, but can be difficult to configure. Here's how I got it working.

I'm using the very nice JGroups-AWS project https://github.com/meltmedia/jgroups-aws. In my configuration, you can see that I use "tags=Env,Role". This means that any given server will query EC2 to find out the values of those tags for itself. For example, suppose the server wakes up and finds that it has Env=Production and Role=API_Server. It will look for other servers with the same tag values (using the AWS webservice endpoints) and form a cluster with them. It checks back periodically so that if servers enter or leave the group it will adjust periodically. Very nice.

The 1.3.0 jgroups-aws uses JGroups 3.1.0, which is a bit out of date. I have not tried forcing a later version in the POM yet. I also cannot completely vouch for all the protocols set up in the ehcache.