Skip to content

Instantly share code, notes, and snippets.

@fphilipe
fphilipe / main.m
Created August 21, 2012 09:01
Objective-C -hash method clash
// This code demonstrates -hash collision on NSString. Two strings have the same
// hash when the first, center, and last 32 chars are identical. The other chars
// don't matter at all.
//
// I had to find this out the hard way when loading images from cache while
// using the url string hash as the cache key. Unfortunately the urls were all
// gravatar urls, thus first 32 chars were identical. Further, all urls also had
// a fallback image url appended as query which covered the 32
// center and end chars. The varying part was between the start and center parts
// and thus the hash was identical for all urls.
@shesek
shesek / template-auto-escaping.js
Created July 20, 2011 11:49
Underscore.js templates escaping support
_.extend(_.templateSettings, {
encode: /<%=([\s\S]+?)%>/g,
interpolate : /<%==([\s\S]+?)%>/g
});
_.extend(_, {
// Taken from Backbone.js's escapeHTML()
escape: function(string) {
return (''+string).replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g,'&#x2F;');
},
template: function(str, data) {
@cweedall
cweedall / waitress (gunicorn alternative) in Python (for Windows OS)
Last active April 26, 2024 08:39
`waitress` / `waitress-serve` is `gunicorn` alternative for Python-based WSGI web app (like Django) on Windows
# Run a WSGI web app (like Django) on Windows
# see: https://stackoverflow.com/a/48542020/7363740
# Install if necessary
conda install waitress
pip install waitress
# Replace standard `gunicorn` command with `waitress-serve`
# for example: gunicorn --listen=*:8000 myapp.wsgi:application
waitress-serve --listen=*:8000 myapp.wsgi:application
@patrickpissurno
patrickpissurno / linear_regression.sql
Last active April 26, 2024 08:39
Simple linear regression and prediction in PL/pgSQL (PostgreSQL)
-- This code is based on my other Gist "Simple linear regression in Javascript" (https://gist.github.com/patrickpissurno/ea0dc4039f075fbaf398619761bd9044)
-- There might be a more efficient way to do this in SQL
-- This function is resposible for computing the weights for the ax + b equation
CREATE OR REPLACE FUNCTION linear_regression(x_array decimal(15,2)[], y_array decimal(15,2)[]) RETURNS decimal(15,2)[] AS $$
DECLARE
slope decimal(15,2);
intercept decimal(15,2);
n integer;
@Kkkassini
Kkkassini / scierc_train_dev_sentences.txt
Last active April 26, 2024 08:38
scierc_train_dev_sentences
English is shown to be trans-context-free on the basis of coordinations of the respectively type that involve strictly syntactic cross-serial agreement.
The agreement in question involves number in nouns and reflexive pronouns and is syntactic rather than semantic in nature because grammatical number in English, like grammatical gender in languages such as French, is partly arbitrary.
The formal proof, which makes crucial use of the Interchange Lemma of Ogden et al., is so constructed as to be valid even if English is presumed to contain grammatical sentences in which respectively operates across a pair of coordinate phrases one of whose members has fewer conjuncts than the other; it thus goes through whatever the facts may be regarding constructions with unequal numbers of conjuncts in the scope of respectively, whereas other arguments have foundered on this problem.
In this paper, a novel method to learn the intrinsic object structure for robust visual tracking is proposed.
The basic assumption is that the
/* Mozilla Ubiquity Command for diigo, currently only support add bookmark.
* Some code from https://ubiquity.mozilla.com/standard-feeds/social.js
*/
var store = Application.storage;
const diigo_CUR_LOGIN = "ubiquity_diigo_cur_login";
var Choices = {"yes": "y", "no": "n"};
var noun_type_share = {
_name: "yes/no",
suggest: function( text, html ) {
@tanaikech
tanaikech / submit.md
Last active April 26, 2024 08:37
Retrieving Release Notes of Google Apps Script and Google APIs from RSS using Google Apps Script

Retrieving Release Notes of Google Apps Script and Google APIs from RSS using Google Apps Script

This is a sample script for retrieving the release notes of Google Apps Script and Google APIs from RSS using Google Apps Script.

Recently, the release notes of Google Apps Script and Google APIs have been published as RSS. By this, the data got to be able to be easily retrieved using XmlService of Google Apps Script. Knowing the latest release notes will be useful for developing the applications. So, I would like to introduce the sample script for retrieving this information.

Sample script

Please copy and paste the following script to the script editor of Google Spreadsheet. And please set the variables in main function.

@stepp1
stepp1 / abstracts.txt
Last active April 26, 2024 08:36
papers.txt
Lossy Compression for Lossless Prediction: Most data is automatically collected and only ever "seen" by algorithms. Yet, data compressors preserve perceptual fidelity rather than just the information needed by algorithms performing downstream tasks. In this paper, we characterize the bit-rate required to ensure high performance on all predictive tasks that are invariant under a set of transformations, such as data augmentations. Based on our theory, we design unsupervised objectives for training neural compressors. Using these objectives, we train a generic image compressor that achieves substantial rate savings (more than $1000\times$ on ImageNet) compared to JPEG on 8 datasets, without decreasing downstream classification performance.
Recent Advances in Autoencoder-Based Representation Learning: Learning useful representations with little or no supervision is a key challenge in artificial intelligence. We provide an in-depth review of recent advances in representation learning with a focus on autoencoder-b
@no-defun-allowed
no-defun-allowed / dbyol.org
Last active April 26, 2024 08:35
Don't Build Your Own Lisp

Don’t Build Your Own Lisp

I feel somewhat pressed to give a negative review of this book. This comes from someone who has worked on various Lisp implementations, and written some amount of C, but that isn’t an excuse to be overly harsh. This book, however, does not provide many nice things to say, and plenty of un-nice things. My apologies in advance.

First off: God help you if you are going to write your first interpreter in C of all things. No one I know thinks it’s a good idea to start

@jeremysears
jeremysears / gremlin-cheat-sheet.md
Last active April 26, 2024 08:35
Gremlin Cheat Sheet in Groovy

Gremlin Cheat Sheet in Groovy

Gremin traversal examples taken from the excellent DS330: DataStax Enterprise Graph course.

Creating Vertices and Vertex Properties

Add a Vertex

Vertex u = graph.addVertex("user");
       u.property("userId","u2016");
 u.property("age",36);