Skip to content

Instantly share code, notes, and snippets.

View mombrea's full-sized avatar

Matt Mombrea mombrea

View GitHub Profile
@mombrea
mombrea / Twitter URL Parsers
Created September 17, 2013 18:08
JavaScript prototype functions to parse out twitter action items into HTML
//Twitter Parsers
String.prototype.parseURL = function() {
return this.replace(/[A-Za-z]+://[A-Za-z0-9-_]+.[A-Za-z0-9-_:%&~?/.=]+/g, function(url) {
return url.link(url);
});
};
String.prototype.parseUsername = function() {
return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) {
var username = u.replace("@","")
return u.link("https://twitter.com/"+username);
@mombrea
mombrea / copy-textview.java
Created October 25, 2013 14:23
Example of copying a textview in android on a button click
public void btnCopyClicked(View view){
LinearLayout container = (LinearLayout)view.findViewById(R.id.container_id);
TextView txt1 = (TextView)view.findViewById(R.id.txtView_id);
TextView txt2 = new TextView(this); //this = context
txt2.setText(txt1.getText());
conatiner.addView(txt2);
}
@mombrea
mombrea / volley-POST-example.java
Last active May 24, 2023 10:58
Example of performing a POST request using Google Volley for Android
public static void postNewComment(Context context,final UserAccount userAccount,final String comment,final int blogId,final int postId){
mPostCommentResponse.requestStarted();
RequestQueue queue = Volley.newRequestQueue(context);
StringRequest sr = new StringRequest(Request.Method.POST,"http://api.someservice.com/post/comment", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mPostCommentResponse.requestCompleted();
}
}, new Response.ErrorListener() {
@Override
@mombrea
mombrea / FileRetriever.cs
Created December 17, 2013 15:41
An example of a custom configSection handler for .NET
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Example
{
#!/bin/bash
#Copyright 11.11.13 Michell Gailing <gailing.michell@gmail.com>
#It's Licensed under DWWWI 'Do whatever you want with it!'
wget http://www.okean.com/chinacidr.txt
sed -i '1,4d' chinacidr.txt
sed -i 's/ China//g' chinacidr.txt
ipset create china hash:net
while read line; do ipset add china $line; done < chinacidr.txt
iptables -I INPUT -m set --match-set china src -j DROP
rm chinacidr.txt
@mombrea
mombrea / countryblock.sh
Created December 26, 2013 16:51
Block a list of IP ranges using IPSet and IPTables
#!/bin/bash
#Script to process ip ranges to ban using IPSet and IPTables
ipset create countryblock hash:net
while read line; do ipset add countryblock $line; done < blocklist.txt
iptables -I INPUT -m set --match-set countryblock src -j DROP
@mombrea
mombrea / iOS-UploadImage.h
Created January 17, 2014 01:49
example of a multi-part form post in objective-c
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"REST URL PATH"]];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setHTTPShouldHandleCookies:NO];
[request setTimeoutInterval:60];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"unique-consistent-string";
@mombrea
mombrea / AppDelegate.m
Created February 4, 2014 22:02
Example of enabling background app refresh and updating the app icon badge number
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
return YES;
}
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if ([[ItemManager new] reloadItemDataSynchronous]) {
ItemHelper *helper = [ItemHelper new];
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
@mombrea
mombrea / ThreadedComments.java
Created July 15, 2014 14:49
Threaded Comments
public static List<Comment> toThreadedComments(List<Comment> comments){
//comments should be sorted by date first
//The resulting array of threaded comments
List<Comment> threaded = new ArrayList<Comment>();
//An array used to hold processed comments which should be removed at the end of the cycle
List<Comment> removeComments = new ArrayList<Comment>();