Skip to content

Instantly share code, notes, and snippets.

@jcheong0428
jcheong0428 / lmer-in-python.ipynb
Last active May 17, 2024 07:23
LMER in Python.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@namklabs
namklabs / rotateArrayRight.js
Created April 26, 2016 04:23
rotate a 2D (2 dimensional) array clockwise (right) by 90 degrees in JavaScript
function rotateArrayRight( arr ){
// rotates a 2D array 90 degrees to the right (clockwise)
var newarr = [];
for( var x = 0; x < arr[0].length; x++ ){
newarr[x] = [];
for( var y = arr.length - 1; y >= 0; y-- ){
newarr[x].push( arr[y][x] );
}
@holmberd
holmberd / php-pools.md
Last active May 17, 2024 07:21
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log

GraphQL

GraphQL is a data query language developed internally by Facebook in 2012 before being publicly released in 2015. It provides an alternative to REST and ad-hoc webservice architectures. It allows clients to define the structure of the data required, and exactly the same structure of the data is returned from the server. It is a strongly typed runtime which allows clients to dictate what data is needed. This avoids both the problems of over-fetching as well as under-fetching of data. GraphQL has been implemented in multiple languages, including JavaScript, Python, Ruby, Java, C#, Scala, Go, Elixir, Erlang, PHP, Python and Clojure.

Official websites:

@anhar
anhar / stylus_dark_mode_styles.json
Created September 21, 2020 23:01
Using browser plugin stylus to override websites CSS styles to dark mode because too much white background color makes my eyes bleed.
This file has been truncated, but you can view the full file.
[
{
"enabled": true,
"updateUrl": "https://stylishthemes.github.io/GitHub-Dark/github-dark.user.css",
"md5Url": null,
"url": "https://github.com/StylishThemes/GitHub-Dark",
"originalMd5": null,
"installDate": 1588038024048,
@mpilosov
mpilosov / GettingStartedWithGRBL.md
Last active May 17, 2024 07:20
Controlling Machines with GRBL

Instructions for a machine with GRBL already on it

My machine (basically this build: https://www.thingiverse.com/thing:1514145) has GRBL 0.9 : https://github.com/grbl/grbl/wiki/Configuring-Grbl-v0.9 The documents for newer version are up there too, obviously. It would definitely be good to get v1.1 working in order to learn the process of getting it on a fresh Arduino board. I'll outline the process of how to do that in the section below this one and fill in the details as I get around to figuring them out. Here's what I do know for sure though...

Sending GCode to the Machine

You can use any number of GUIs but the premise is always the same. Once the firmware is on your board, connect it via USB, power it on, and search in your /dev/ directory for your Arduino (type that into Terminal and start typing "tty" and then hit Tab until something shows up). If you have the Arduino software, use the drop down menus to identify an address like /dev/ttyusb#### or /dev/wchusbserial#### The numbers will be u

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.

@martindrapeau
martindrapeau / planbox_time_report.js
Created October 13, 2011 15:04
Planbox Current Iteration Time Report
var stories;
var resources;
function doWork() {
var sums = {};
for (var i=0; i < resources.length; i++) {
var resource = resources[i];
sums[resource.id] = {
name: resource.name,
stories: {},
estimate: 0,
@martindrapeau
martindrapeau / planbox_burndown_data.js
Created October 13, 2011 15:10
Planbox Burndown Data in Current Iteration
var iteration;
function doWork() {
var burndown = iteration.burndown;
var product_data = burndown.data[0];
var dates = burndown.dates;
console.log('Points remaining in iteration');
for (var i=0; i&lt;dates.length; i++) {
var remain = product_data.points[i];
if (remain != null) {