Skip to content

Instantly share code, notes, and snippets.

@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
@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){
@geoffreydhuyvetters
geoffreydhuyvetters / react_fiber.md
Last active August 15, 2024 15:17
What is React Fiber? And how can I try it out today?
@bvaughn
bvaughn / react-lifecycle-cheatsheet.md
Last active January 4, 2026 21:31
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
<?php
class fileManagerFacade {
private $fileSync = null;
private $elFinder = null;
private $connector = null;
private $rootDirName = 'files-manager';
private $visibleFileTypes = [];
<?
class leafFile extends leafBaseObject
{
const tableName = 'leafFiles';
const defaultFolderMode = 0775; // rwx rwx r-x
const defaultFileMode = 0666; // rw- rw- rw-
const inputFieldSuffix = '_hash';
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord', '5.2.0'
gem 'memory_profiler'
gem 'benchmark-ips'
end
@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/