Skip to content

Instantly share code, notes, and snippets.

@syphoxy
syphoxy / throttle.js
Created March 25, 2013 15:41
this is a simple example of how to throttle the window resize event.
$(function() {
var throttle;
$(window).resize(function() {
clearTimeout(throttle);
throttle = setTimeout(function() {
/* resize code */
}, 100);
});
#!/bin/bash
while true
do
PASSWORD_LENGTH=20
password="$(head -n5 /dev/urandom | strings | tr -c '[:alnum:]' ' ' | tr -d '[:space:]' | cut -b1-$PASSWORD_LENGTH)"
[ "$(echo -n "$password" | wc -c)" -ne $PASSWORD_LENGTH ] || break
done
@syphoxy
syphoxy / transmission-sorted
Last active February 29, 2024 23:30
sort transmission-remote -l output
#!/bin/bash
# Default parameters
OptSortColumn=none
OptSortReverse=0
ProxyArguments=()
# Parse parameters
for param in "$@"
do
@syphoxy
syphoxy / original.php
Last active January 3, 2016 12:29
Refactoring Magento code by example
<?php
protected function _getMemoryLimit()
{
$memoryLimit = trim(strtoupper(ini_get('memory_limit')));
if (!isSet($memoryLimit[0])){
$memoryLimit = "128M";
}
@syphoxy
syphoxy / search-chatsync
Last active January 4, 2016 00:49
search skype for mac chatsync data for keywords: $ bash search-chatsync "your phrase here"
#!/bin/bash
echo -n "Searching for '$1' in chatsync .. "
find "$HOME/Library/Application Support/Skype" -type d -name chatsync -print0 \
| xargs -0 -I{} find {} -type f -name '*.dat' \
| while read syncFile
do
(strings "$syncFile" | fgrep -qi "$1") \
&& (strings "$syncFile" | less -p"$1")
BEGIN {
headerString = ""
footerString = ""
inactiveCount = 0
split("", inactiveTorrents)
activeCount = 0
split("", activeTorrents)
}
<!-- Your mixed HTML+PHP page script (pseudo-code) -->
<?php mysql_connect(/* database details */) ?>
<?php $result = mysql_query(/* get current page from db */) ?>
<?php $page = mysql_fetch_assoc($result) ?>
<html>
<head>
<title><?php echo htmlentities($page['title']) ?></title>
</head>
<body>
<h1><?php echo htmlentities($page['title']) ?></h1>
@syphoxy
syphoxy / .zshrc
Last active August 29, 2015 14:00
show machine name in zsh prompt if connected through ssh
function precmd {
local SSH_STATUS=""
if [ -n "$SSH_CONNECTION" ]
then
SSH_STATUS="%m "
fi
PROMPT="${SSH_STATUS}%1~ %B%#%b "
}
@syphoxy
syphoxy / generator.php
Created April 21, 2014 17:49
experimental html generator from array data structure
<?php
$structure = array(
'html' => array(
'children' => array(
'head' => array(
'children' => array(
'title' => array(
'children' => array(
'Hello, World'
<?xml version="1.0"?>
<config>
<modules>
<Acme_Module>
<active>true</active>
<codePool>local</codePool>
</Acme_Module>
</modules>
</config>