Skip to content

Instantly share code, notes, and snippets.

@tsupo
tsupo / convIsbn.js
Created May 8, 2009 18:43
covert code between ISBN10 and ISBN13
/* convISBN.js : converter ISBN10 <-> ISBN13 */
/* Copyright (c) 2007 by H.Tsujimura <tsupo@na.rim.or.jp> */
/* Distributed by LGPL. */
/* this script written by H.Tsujimura 20 Jan 2007 */
function convISBN13toISBN10(str) {
var s;
var c;
var checkDigit = 0;
var result = "";
@fnichol
fnichol / README.md
Created March 12, 2011 20:52
Download a cacert.pem for RailsInstaller

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

@stevenhaddox
stevenhaddox / server_certificates_to_pem.md
Last active December 14, 2023 05:42
Convert .crt & .key files into .pem file for HTTParty

Two ways to do it, but only worked for me so I'll put it first and the second for reference:

$ openssl pkcs12 -export -in hostname.crt -inkey hostname.key -out hostname.p12
$ openssl pkcs12 -in hostname.p12 -nodes -out hostname.pem

Other options for this method in comments below:

# Note, the -certfile root.crt appends all CA certs to the export, I've never needed these so it's optional for my personal steps
$ openssl pkcs12 -export -in hostname.crt -inkey hostname.key -certfile root.crt -out hostname.p12

Note, I've always had my hostname.crt as part of my .pem, so I keep my certs but apparently you may not have to, hence the nocerts flag being an extra option in this sample

@HakanL
HakanL / HighPrecisionTimer
Created January 30, 2013 00:34
C# code for a High Precision Timer (avg <1 ms for 25 ms interval). Fair use of CPU time. Uses NLog to log accuracy
using NLog;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Animatroller.Framework.Utility
{
public class HighPrecisionTimer : IDisposable
{
@troystribling
troystribling / RememberMeAuthStrategy.scala
Last active January 1, 2017 08:32
Scalatra 2.2 Sentry implemented for username/password and cookie authentication.
package lib
import org.scalatra._
import org.scalatra.util.RicherString._
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
import org.scalatra.auth.{ScentrySupport, ScentryStrategy}
import net.iharder.Base64
import java.util.Locale
import io.Codec
@mrded
mrded / foo.module
Created October 31, 2013 13:46
Drupal: Taxonomy terms as autocomplete using form API.
<?php
function bar_form($form, &$state) {
$form['bar'] = array(
'#type' => 'textfield',
'#title' => t('Bar'),
'#autocomplete_path' => 'taxonomy/autocomplete/field_bar_term', // Field name here.
'#element_validate' => array('foo_taxonomy_autocomplete_validate'),
);
@ilguzin
ilguzin / nginx_redirect_2named_location
Created November 6, 2013 07:03
NGINX: Redirect from current location into named location
# Use only codes greater than 418, do not use common status codes 404, 402, 403, etc
location /js {
error_page 418 = @backend; return 418;
}
location /data {
error_page 418 = @backend; return 418;
}
@bryanbarnard
bryanbarnard / SimpleHttpClient.cs
Created December 23, 2013 19:15
Simple C# .NET 4.5 HTTPClient Request Using Basic Auth and Proxy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net;
namespace HTTP_Test
@Antarix
Antarix / LocalBroadcastExampleActivity.java
Created December 26, 2013 08:31
Simple Example of using LocalBroadcastManager in Android
import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.LocalBroadcastManager;
@arigesher
arigesher / responsive-flickr-embeds
Last active October 26, 2020 08:20
JQuery code to make Flickr embeds responsive (and resize correctly when loading in a mobile browser). See http://ari.gesher.net/photos-the-gesher-world-tour/ for a working example.
$(document).ready(function() {
$("#pics iframe").each(function(index) {
var ratio = $(this).height() / $(this).width();
var origHeight = $(this).height();
var origWidth = $(this).width();
var self = this;
// bind to window with closure that references the
// iframe since the iframe doesn't get resize events
// until (you know) we resize it.
$(window).resize(function() {