Skip to content

Instantly share code, notes, and snippets.

View rochacon's full-sized avatar

Rodrigo Chacon rochacon

  • Remote
  • 20:25 (UTC -03:00)
View GitHub Profile
@perusio
perusio / gist:1326701
Created October 31, 2011 01:28
Mobile device detection in Nginx with just 7 lines of configuration
### Testing if the client is a mobile or a desktop.
### The selection is based on the usual UA strings for desktop browsers.
## Testing a user agent using a method that reverts the logic of the
## UA detection. Inspired by notnotmobile.appspot.com.
map $http_user_agent $is_desktop {
default 0;
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
~*spider|crawl|slurp|bot 1; # bots
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
@rduplain
rduplain / MainActivity.java
Created May 8, 2012 20:08
A very simple full-screen WebView activity for Android native wrappers, as a starting point.
package com.willowtreeapps.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
@border
border / long_polling.go
Created September 25, 2012 09:58
long polling for golang
package main
import (
"container/list"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
@mschoebel
mschoebel / main.go
Created March 6, 2014 20:02
Snippet: login/logout (Golang)
package main
import (
"fmt"
"github.com/gorilla/mux"
"github.com/gorilla/securecookie"
"net/http"
)
// cookie handling
@jontg
jontg / gist:9745186
Last active February 25, 2016 10:08
Zero Downtime
#!/bin/bash
# Source files so we can announce stuff
. /mnt/apps/scripts/setenv.sh
. /mnt/apps/scripts/hipchat_notify.sh
if [ $(pidof -x deploy_if_new.sh | wc -w) -gt 2 ]; then
echo "$(date +"%Y-%m-%d %H:%M:%S %Z") Cowardly exiting as deploy_if_new is already running"
exit -1
fi
@canassa
canassa / fix_pytest.py
Last active December 8, 2015 08:59
Converts self.assertEquals to assert
"""
Replaces unittest style asserts (e.g.: self.assertEqual) with py.test style asserts
Usage:
from lib2to3.refactor import RefactoringTool
refactoring_tool = RefactoringTool(['fix_pytest'])
refactoring_tool.refactor(['input.py'], write=True)
"""
echo "set_wallpaper()" | awesome-client
@julz
julz / main.go
Created November 20, 2015 12:39
containersched minicontainer
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func main() {
@achauve
achauve / slack_deploy_bot_template.py
Last active November 20, 2020 05:29
Template of Slack bot for deployment
import logging
import os
import time
import traceback
# pip install slackclient
from slackclient import SlackClient
@andrei-markeev
andrei-markeev / get-data-from-excel.js
Created November 15, 2016 10:09
Get data from Excel file stored in SharePoint using Excel REST API
var fileRelativeUrl = "Shared%20Documents/book1.xlsx";
var sheetName = "Sheet1";
var range = "A1|J45";
var url = _spPageContextInfo.webServerRelativeUrl.replace(/\/$/, '') + "/";
loadXMLDoc(url + "_vti_bin/ExcelRest.aspx/" + fileRelativeUrl + "/model/Ranges('" + sheetName + "!" + range + "')?$format=atom", function (text) {
var parser = new DOMParser();
var excelRestNS = 'http://schemas.microsoft.com/office/2008/07/excelservices/rest';
var xmlDoc = parser.parseFromString(text, "text/xml");
var rows = xmlDoc.getElementsByTagNameNS(excelRestNS, 'row');