Skip to content

Instantly share code, notes, and snippets.

@CS1000
CS1000 / crazySwap.js
Last active August 29, 2015 14:07
Swap ALL the <div>s
javascript:setInterval(function(){d=document.querySelectorAll('div');
l=d.length;a=d[parseInt(Math.random()*l)];b=d[parseInt(Math.random()*l)];
c=a.innerHTML;a.innerHTML=b.innerHTML;b.innerHTML=c;}, 42)
@CS1000
CS1000 / rel=prev.js
Last active August 29, 2015 14:07
A rel="prev"
javascript:document.location.href=document.querySelector("a[rel=prev]").href
@CS1000
CS1000 / mysql_ snippet.md
Last active August 29, 2015 14:07
ext/mysql snippet

***Notice:*** There is **no more support** for `mysql_*` functions, they are [**officially deprecated**](https://wiki.php.net/rfc/mysql_deprecation), **no longer maintained** and will be [**removed**](http://php.net/manual/en/function.mysql-connect.php#warning) in the future. You should update your code with [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) to ensure the functionality of your project in the future.

>Notice: There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future.

@CS1000
CS1000 / broscript.js
Created September 24, 2014 23:20
Bro Script (so chat)
Paste in SO chat room console bro:
(function() {
"use strict";
var chat = document.getElementById('chat');
function parseNode(node) {
if (node.classList
&& node.classList.contains('message')
&& !node.classList.contains('pending')
&& !node.querySelector('.onebox')
@morrisonlevi
morrisonlevi / loops.php
Last active December 16, 2015 20:29
Empty Loop Micro-benchmarks. Useless except for curiosity.
<?php
define('ITERATIONS', 10000000);
$var = 0;
$start = microtime(true);
$var = 0;
while ($var < ITERATIONS) {
++$var;
}
@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:

@hakre
hakre / README.md
Last active September 26, 2015 13:17
Former Print_r Converter Gist, now gone full-blown: https://github.com/hakre/print_r-converter

Print_r Converter

As of September 2013, the repository has been moved from this Github Gist (hakre/1102761) over to a public Github repository in my account. You can find it now here:

Please visit that address for more information, updates and code.