Skip to content

Instantly share code, notes, and snippets.

@wrimik
wrimik / fedex-rates-nodejs-soap-example.js
Last active January 25, 2022 18:19
FedEx Rates NodeJS SOAP Request
var soap = require('soap'); // npm i soap
var url = 'fedex-api/RateService/RateService_v24.wsdl'; // you'll need to download the wsdl file from https://www.fedex.com/en-us/developer/web-services/process.html#StandardServices
// if you change the order of these variables, everything gets fucked up because "wsdl" is a format for developers who have
// landed themselves in a middle circle of hell.
// this points at fedex's production server btw. if you use dev credentials you'll need to change the url WAAAY down
// by the bottom of the file, in "client.setEndpoint('https://ws.fedex.com:443/web-services');"
var data = {
"WebAuthenticationDetail": {
"UserCredential": {
@butuzov
butuzov / mp3 to m4b.md
Created August 10, 2018 06:07
Convert mp3's to m4b using `ffmpeg`

Let's imagine we have a lot of mp3 files ( forexample one of the pluralsite courses converted to mp3 ).

URL=https://www.pluralsight.com/courses/run-effective-meetings
PASS=pass
USER=user
OUTPUT="%(playlist_index)s. %(title)s-%(id)s.%(ext)s"
youtube-dl --username $USER --password $PASS -o $OUTPUT --extract-audio --audio-format mp3 $URL
# This is targetted towards people using a user for each website.
# Give back its own files to your user
chown -R user:user ~user/public_html
# Copy user permissions to group permissions
chmod -R g=u ~user/public_html
# Disallow other users from everything on your files
chmod -R o-rwx ~user/public_html
@senderista
senderista / ps_queue_sim.js
Created August 27, 2015 05:20
A simple processor-sharing queue simulator in node.js
var PoissonProcess = require('poisson-process');
var sleep = require('sleep');
var http = require('http');
var port = process.env.PORT || 1337;
var TIMESLICE_MILLIS = 1;
var MEAN_SLEEP_MILLIS = 500;
function sleep_for_timeslice(total_ms, ms_left, req_timestamp, res) {
if (ms_left > 0) {
sleep.usleep(TIMESLICE_MILLIS*1000);
@sarciszewski
sarciszewski / README.md
Created May 30, 2015 04:25
A Crusade Against Bad Code

Aniruddh Agarwal blogged A short tour of PHP, and this is one of the negatives he identified:

Community: I know. I said that PHPs community was an advantage to it, but it is also a disadvantage, because of BAD CODE. Beginners are not taught the best practices and they go on to write bad code and distribute it, either as answers on Stack Overflow or similar websites or blog about it, which encourages other beginners to adopt those practices. There is a lot of misinformation out there, and it is very difficult to separate the good from the bad. This is perhaps the worst thing about PHP, because PHP is an entry-level language and people learning it are usually not aware of the best practices.

This is spot on!

The existence of BAD CODE being copied and pasted by newcomers is probably the biggest source of exploitable security vulnerabilities in the entire industry.

The biggest offenders are often the highest ranking search results on Google and other search eng

@b00gizm
b00gizm / LoginOrSignupType.php
Created July 12, 2013 13:21
Adding a validation constraint in Symfony2 based on the existence and value of a form field via Symfony's form events. Good idea (best practice?) or dirty hack..?
<?php
namespace T7\Bundle\OAuthBundle\Form;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\ExecutionContextInterface;
@justinph
justinph / validate_gravatar.php
Created March 19, 2013 16:49
In wordpress, a better way to check if an author has a gravatar or not. Sometimes you might want to check to see if a gravatar exists and not display any image if there isn't one. Uses the wordpress HTTP and caching apis. A better version of this: http://codex.wordpress.org/Using_Gravatars#Checking_for_the_Existence_of_a_Gravatar
/**
* Utility function to check if a gravatar exists for a given email or id
* @param int|string|object $id_or_email A user ID, email address, or comment object
* @return bool if the gravatar exists or not
*/
function validate_gravatar($id_or_email) {
//id or email code borrowed from wp-includes/pluggable.php
$email = '';
@ryanjbonnell
ryanjbonnell / gist:4611642
Last active November 21, 2018 06:48
Install lynx on Mac OS X 10.8 "Mountain Lion"
cd /usr/local/src
curl -O http://lynx.isc.org/lynx2.8.7/lynx2.8.7.tar.gz
tar -xzvf lynx2.8.7.tar.gz
cd lynx2-8-7
./configure --mandir=/usr/share/man
make
sudo make install
@jaredhirsch
jaredhirsch / howto-detumblrize.mkd
Last active January 22, 2021 20:55
Downloading stuff off of tumblr

TL;DR skip to the summary for the bash one-liner if so inclined :-)

Why & wherefore

I have an old tumblr that I want to back up. I don't use it regularly, but I want to have a backup of the whole site, design as well as content, just in case; it's not just the pictures I love, but the whole thing. I'm not particularly worried about downloading the streaming audio--can't help you there, gentle reader.

@mikejolley
mikejolley / gist:2044101
Last active May 18, 2021 17:02
WooCommerce - Show number of items in cart and total
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>