Skip to content

Instantly share code, notes, and snippets.

View ekinhbayar's full-sized avatar

Ekin ekinhbayar

View GitHub Profile
@Girgias
Girgias / steps.md
Last active December 5, 2020 12:47
How to commit a Git patch to SVN for the PHP Documentation

This assumes 2 copies of the PHP documentation repo, one "official" SVN which is meant to be kept clean, and a fork of php/doc-en

After the doc PR has been reviewed/approved/decided to merge, squash it into one commit (make sure the branch is up to date with upstream).

Assumed file structure

For the purpose of this tutorial, the following file structure is assumed:

|
|-- doc-en the Git fork
| |(content of English documentation)
<!doctype html>
<!-- This is just a very slightly modified tracking.js demo: https://trackingjs.com/examples/face_camera.html -->
<html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/tracking.js/1.1.3/tracking-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tracking.js/1.1.3/data/face-min.js"></script>
<style>
video, canvas {
margin-left: 100px;
# 1000 concurrent HTTP requests to 127.0.0.1 where default nginx is sitting
# Using golang
[ralt@zap golang]$ time ./golang
real 0m0.083s
user 0m0.165s
sys 0m0.087s
[ralt@zap golang]$ time ./golang
@DaveRandom
DaveRandom / script.js
Last active June 6, 2018 09:36
Tweet icon for Jeeves in SO chat
// ==UserScript==
// @name Tweet icon for Jeeves in SO chat
// @namespace http://room11.org/
// @version 1.0
// @description @PeeHaa sucks
// @author @DaveRandom
// @match *://chat.stackoverflow.com/rooms/*
// @grant none
// ==/UserScript==

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@ulgens
ulgens / brown-taggedwords.py
Last active October 16, 2016 11:34
Export Brown Corpus tagged words by categories using NLTK. Based on: https://gist.github.com/JonathanReeve/ac543e9541d1647c1c3b
from nltk.corpus import brown
for category in brown.categories():
words = brown.tagged_words(categories=category)
text = '\n '.join('%s, %s' % word for word in words)
filename = category + '.txt'
with open(filename, 'w') as outfile:
outfile.write(text)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// XMLDecl from http://www.w3.org/TR/xml/#xmldoc
$regex = <<<'REGEX'
/
(?(DEFINE)
(?<S> [\x20\x9\xD\xA]+ )
(?<Eq> (?&S)? = (?&S)? )
)
^(?<XMLDecl>
<\?xml
(?<VersionInfo>
@nikic
nikic / objects_arrays.md
Last active April 12, 2024 17:05
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@imkevinxu
imkevinxu / .gitconfig
Created November 5, 2012 09:42
`git random` alias that will commit a random commit message from http://whatthecommit.com/
[alias]
random = !"git add -A; git commit -am \"$(echo $(curl -s http://whatthecommit.com/index.txt)\" (http://whatthecommit.com)\")\"; git pull --rebase; git push"