Skip to content

Instantly share code, notes, and snippets.

View ximus's full-sized avatar

Maxime Liron ximus

View GitHub Profile
@ximus
ximus / change tracking.rb
Last active October 20, 2023 13:54
5min illustration of cheap and dirty change tracking with activerecord
# WARN: this relies on the single threaded nature of our apps!
class ApplicationModel < ActiveRecord::Base
before_save do
if ChangeTracking.currently_change_tracking?
changeset << [:update, self, changes]
end
end
before_create do
@ximus
ximus / react-portal.js
Last active October 8, 2018 06:58
react singleton/portal
import ReactDOM from 'react-dom';
/**
* Mount a component elsewhere than where it is declared in the markup.
*
* example use:
* import portal from 'common-util/reactPortal';
* import MyModal from 'MyModal'
*
* // you must specify the DOM node to mount to by specifying a DOM node factory.
@ximus
ximus / ubilinux-flashall-osx.diff
Created March 16, 2015 03:24
get flashall.sh to work on osx
--- flashall.sh
+++ (clipboard)
@@ -220,15 +220,14 @@
flash-command --alt u-boot-env0 -D "${VARIANT_FILE}"
echo "Flashing U-Boot Environment Backup"
- flash-command --alt u-boot-env1 -D "${VARIANT_FILE}" -R
+ flash-command --alt u-boot-env1 -D "${VARIANT_FILE}"
echo "Rebooting to apply partition changes"
- dfu-wait no-prompt
@ximus
ximus / fix prestashop alysum theme promo slider
Created November 15, 2014 20:46
Fix for alysum minic promo slider: Data too long for column 'effect' at row 1
Fresh install of prestashop 1.6.0.9 and Alysum theme 3.1.
Error: `Data too long for column 'effect' at row 1`
Failing sql query:
```
INSERT INTO `ps_minic_options` (
`id_shop`, `effect`
) VALUES (
1,
"random,simpleFade, curtainTopLeft, curtainTopRight, curtainBottomLeft, curtainBottomRight, curtainSliceLeft, curtainSliceRight, blindCurtainTopLeft, blindCurtainTopRight, blindCurtainBottomLeft, blindCurtainBottomRight, blindCurtainSliceBottom, blindCurtainSliceTop, stampede, mosaic, mosaicReverse, mosaicRandom, mosaicSpiral, mosaicSpiralReverse, topLeftBottomRight, bottomRightTopLeft, bottomLeftTopRight, bottomLeftTopRight");
/******************************************************************************
* CC430 RF Code Example - TX and RX (fixed packet length =< FIFO size)
*
* Simple RF Link to Toggle Receiver's LED by pressing Transmitter's Button
* Warning: This RF code example is setup to operate at either 868 or 915 MHz,
* which might be out of allowable range of operation in certain countries.
* The frequency of operation is selectable as an active build configuration
* in the project menu.
*
* Please refer to the appropriate legal sources before performing tests with

Benchmarking Nginx with Go

Today I just wanted to know which of these options is faster:

  • Go HTTP standalone
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI

Hardware

def request(req, body = nil, &block) # :yield: +response+
unless started?
start {
req['connection'] ||= 'close'
return request(req, body, &block)
}
end
if proxy_user()
unless use_ssl?
req.proxy_basic_auth proxy_user(), proxy_pass()
=begin
Message Pack vs similar utilities
ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.0.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02
Packing
user system total real
pack: bert 18.320000 0.770000 19.090000 ( 19.101583)
pack: bson_ext 0.850000 0.030000 0.880000 ( 0.878398)
pack: json_ext 2.540000 0.040000 2.580000 ( 2.582495)
def complementary_pairs(k, a)
matches = 0
a.each_index do |i|
# sum the tail, the elements from i (excluded) to the end of a
(i...a.length).each do |j|
sum = a[i] + a[j]
# we have a match but, ...
if sum == k
# if its the sum of itself, then there can only be one match
if i == j
@ximus
ximus / kcompl.rb
Created September 23, 2012 23:43
Testing max's reasoning
# I'm assuming sum operations are cheap and I won't gain much, if at all, from
# memoizing sums.
def complementary_pairs(k, a)
matches = 0
a.each_index do |i|
# sum the tail, the elements from i (excluded) to the end of a
(i...a.length).each do |j|
sum = a[i] + a[j]
# we have a match but, ...
if sum == k