Skip to content

Instantly share code, notes, and snippets.

@bgrins
bgrins / gist:1789787
Created February 10, 2012 13:58
C# Multipart File Upload
// Implements multipart/form-data POST in C# http://www.ietf.org/rfc/rfc2388.txt
// http://www.briangrinstead.com/blog/multipart-form-post-in-c
public static class FormUpload
{
private static readonly Encoding encoding = Encoding.UTF8;
public static HttpWebResponse MultipartFormDataPost(string postUrl, string userAgent, Dictionary<string, object> postParameters)
{
string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid());
string contentType = "multipart/form-data; boundary=" + formDataBoundary;
@dodyg
dodyg / gist:5823184
Last active October 20, 2024 12:25
Kotlin Programming Language Cheat Sheet Part 1

#Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

// Overriding Backbone.sync to either load locally or from the server
sync: function(method, model, options) {
// Pull the key and stored object localStorage
var storageKey = localStorage.getItem('storage');
var storageData = localStorage.getItem('storage-' + storageKey);
// Apply the callback with our local data
if(storageData) {
options.success(JSON.parse(storageData));
@hellysmile
hellysmile / repositories.py
Last active February 3, 2023 22:27
django repository pattern
from django.contrib.sites.models import Site
class Object(object):
def __init__(self, model, key):
self.model = model
self.key = key
def __call__(self, *args, **kwargs):
params = {}
@danharper
danharper / a.md
Last active September 2, 2020 17:13
Laravel Queue Supervisor

Install Supervisor with sudo apt-get install supervisor. Ensure it's started with sudo service supervisor restart.

In /etc/supervisord/conf.d/ create a .conf file. In this example, laravel_queue.conf (contents below). Give it execute permissions: chmod +x laravel_queue.conf.

This file points at /usr/local/bin/run_queue.sh, so create that file there. Give this execute permissions, too: chmod +x run_queue.sh.

Now update Supervisor with: sudo supervisorctl reread. And start using those changes with: sudo supervisorctl update.

@bcole808
bcole808 / numberAbbreviation.php
Created March 5, 2014 17:18
Shorten large numbers into abbreviations (i.e. 1,500 = 1.5k)
<?php
/**
* Shorten large numbers into abbreviations (i.e. 1,500 = 1.5k)
*
* @param int $number Number to shorten
* @return String A number with a symbol
*/
function numberAbbreviation($number) {
$abbrevs = array(12 => "T", 9 => "B", 6 => "M", 3 => "K", 0 => "");
@craighooghiem
craighooghiem / eloquent.php
Last active November 27, 2021 09:27 — forked from clauddiu/eloquent.php
Using Eloquent outside of Laravel. This specific example was used in a Silex installation.
<?php
require 'vendor/autoload.php';
$settings = array(
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'database',
'username' => 'root',
'password' => 'root',
@tairov
tairov / gist:11289983
Last active October 29, 2020 16:13
php, rabbitmq, delayed messages
// include the AMQPlib Classes || use an autoloader
// queue/exchange names
$queueRightNow = 'right.now.queue';
$exchangeRightNow = 'right.now.exchange';
$queueDelayed5sec = 'delayed.five.seconds.queue';
$exchangeDelayed5sec = 'delayed.five.seconds.exchange';
$delay = 5; // delay in seconds
using Microsoft.Phone.Controls;
using System;
using System.Windows.Controls.Primitives;
/// <summary>
/// This class detects the pull gesture on a LongListSelector. How does it work?
///
/// This class listens to the change of manipulation state of the LLS, to the MouseMove event
/// (in WP, this event is triggered when the user moves the finger through the screen)
/// and to the ItemRealized/Unrealized events.
namespace Audio
{
using System;
using System.IO;
/// <summary>
/// Provides methods for saving byte arrays of audio samples to a wav file in mono or stereo.
/// </summary>
public static class WaveSaver
{