Skip to content

Instantly share code, notes, and snippets.

View robmcalister's full-sized avatar
🐢
Slowly, but surely.

Robbie McAlister robmcalister

🐢
Slowly, but surely.
View GitHub Profile
import re
# Some mobile browsers which look like desktop browsers.
RE_MOBILE = re.compile(r"(iphone|ipod|blackberry|android|palm|windows\s+ce)", re.I)
RE_DESKTOP = re.compile(r"(windows|linux|os\s+[x9]|solaris|bsd)", re.I)
RE_BOT = re.compile(r"(spider|crawl|slurp|bot)")
def is_desktop(user_agent):
"""
@robmcalister
robmcalister / hold.js
Last active January 3, 2016 04:59
Tap and Hold directive for angularjs (rmHold).
app.directive('rmHold', ['$timeout', function($timeout) {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
var isActive = false;
var currentTimeout = null;
var startCoords = {
x: null,
y: null
}
@robmcalister
robmcalister / RequestAnimationFrame.js
Last active January 3, 2016 09:29 — forked from mrdoob/RequestAnimationFrame.js
Request Animation Frame
/**
* Provides requestAnimationFrame in a cross browser way.
* @author paulirish / http://paulirish.com/
*/
if ( !window.requestAnimationFrame ) {
window.requestAnimationFrame = ( function() {
return window.webkitRequestAnimationFrame ||
@nepsilon
nepsilon / 5-ways-to-check-if-a-string-contains-a-substring-in-avascript.md
Last active February 28, 2017 16:15
5 ways to check if a string contains a substring in Javascript — First published in fullweb.io issue #89

5 ways to check if a string contains a substring in Javascript

1. ES6 .includes():

var S = "fullweb";
S.includes("web");

2. RegExp .search():

@shazron
shazron / app.js
Created May 23, 2013 22:03
RequireJS with Cordova example (app.js)
requirejs(['cordova.js'],
function () {
// start of require
// cordova is now available globally
var exec = cordova.require('cordova/exec');
var app = {
// Application Constructor
@nepsilon
nepsilon / 3-vim-tips-with-external-commands.md
Last active December 5, 2018 17:23
3 Vim tips with external commands — First published in fullweb.io issue #95

3 Vim tips with external commands

Vim has this ! special character that will run any shell command without having to close it. Here are 3 ways I often use it:

1. Format a JSON blob:

:%!python -m json.tool

2. Count number of characters in a file:

@joshearl
joshearl / SublimeProjectExample.sublime-project
Created November 17, 2012 02:32
Sample Sublime project file with project-specific settings
{
"folders":
[
{
"path": "Leanpub/sublime-productivity",
"folder_exclude_patterns": ["epub_images", "convert_html", "preview", "published"],
"file_exclude_patterns": [".gitignore", "*.sublime*", "*Icon*"]
},
{
"path": "SublimeTextTips"
@jeffdonthemic
jeffdonthemic / ChatterUtils
Last active April 1, 2019 00:21
Simple Class to add Salesforce Chatter posts with links, urls and mentions.
public with sharing class ChatterUtils {
// makes a simple chatter text post to the specified user from the running user
public static void simpleTextPost(Id userId, String postText) {
ConnectApi.FeedType feedType = ConnectApi.FeedType.UserProfile;
ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
@alicial
alicial / mock-service-example.js
Last active June 10, 2019 14:26
AngularJS: Setting up a mocked service to use in controller unit tests.
// Mocked Service
angular.module('mock.users', []).
factory('UserService', function($q) {
var userService = {};
userService.get = function() {
return {
id: 8888,
name: "test user"
}
@samvermette
samvermette / apn-server.php
Created December 30, 2010 07:40
Quickly send an Apple Push Notification using PHP
<?php
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsCert = 'apns-dev.pem';
$apnsPort = 2195;
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);