Skip to content

Instantly share code, notes, and snippets.

@WJWH
WJWH / c10k.ru
Created October 15, 2018 09:12
The double hijack trick, serving 65k connections from a single ruby process
# This server demo does a socket hijack in Rack and then saves the socket to a global variable
# to prevent it from being GCed when the Puma thread ends. It will then write "BEEP" to each
# socket every ten seconds to prevent the connection timing out. During testing, it easily
# handled up to 65523 connections, after which it ran into the `ulimit` for open file descriptors.
# The bit with the waiting area is there because a normal `Set` is not thread safe and it would
# drop socket due to race conditions. The `Queue` is thread safe and will make sure all sockets
# are preserved.
# run with `rackup -q -p 8000 -o 0.0.0.0 c10k.ru`
# testing: install `ab` and then run `ab -c 20000 -n 20000 <ip adress of server>:8000/
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord', '5.2.0'
gem 'memory_profiler'
gem 'benchmark-ips'
end
<?
class leafFile extends leafBaseObject
{
const tableName = 'leafFiles';
const defaultFolderMode = 0775; // rwx rwx r-x
const defaultFileMode = 0666; // rw- rw- rw-
const inputFieldSuffix = '_hash';
<?php
class fileManagerFacade {
private $fileSync = null;
private $elFinder = null;
private $connector = null;
private $rootDirName = 'files-manager';
private $visibleFileTypes = [];
@bvaughn
bvaughn / react-lifecycle-cheatsheet.md
Last active March 2, 2023 13:29
React lifecycle cheatsheet

React lifecycle cheatsheet

Method Side effects1 State updates2 Example uses
Mounting
componentWillMount Constructor equivalent for createClass
render Create and return element(s)
componentDidMount DOM manipulations, network requests, etc.
Updating
componentWillReceiveProps Update state based on changed props
@geoffreydhuyvetters
geoffreydhuyvetters / react_fiber.md
Last active January 13, 2023 06:49
What is React Fiber? And how can I try it out today?
@mungurs
mungurs / leafFileSync.php
Created December 14, 2016 11:55
elFinder file sync. with db
<?php
class leafFileSync{
private $enableLog = false;
public function __construct($logSynchronization = false){
$this->enableLog = $logSynchronization;
}
public function sync($cmd, $result, $args, elFinder $elFinder, elFinderVolumeDriver $volume){
@theHamdiz
theHamdiz / flexible interface.rb
Last active April 17, 2018 15:33
Learn how to build flexible interfaces using instance_eval in #ruby
class Person
def name(n)
@name = n
self
end
def age(a)
@age = a
self
end
@derwiki
derwiki / README.md
Last active September 27, 2023 17:50
Ruby module that you can use in a `before_action` on sensitive controllers for which you'd like a usage audit trail

Adding an audit log to your Rails app

If you have any sort of administrative interface on your web site, you can easily imagine an intruder gaining access and mucking about. How do you know the extent of the damage? Adding an audit log to your app is one quick solution. An audit log should record a few things:

  • controller entry points with parameter values
  • permanent information about the user, like user_id
  • transient information about the user, like IP and user_agent

Using the Rails framework, this is as simple as adding a before_action to your admin controllers. Here’s a basic version that I’m using in production.

@andrei-cacio
andrei-cacio / react-native-setup-linux.md
Last active June 22, 2018 21:22
React native setup on Ubuntu/Linux

Guide for installing React Native on Linux (ubuntu 14.04)

Step 1: Install JDK 7

sudo apt-get install openjdk-7-jdk

Step 2: Download the Android SDK