Skip to content

Instantly share code, notes, and snippets.

View attacomsian's full-sized avatar
🌱
Fore Studio

Atta ✨ attacomsian

🌱
Fore Studio
View GitHub Profile
@matoakley
matoakley / gist:1092571
Created July 19, 2011 14:38
MySQL to convert a string into a slug
LOWER(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(TRIM('My String'), ':', ''), ')', ''), '(', ''), ',', ''), '\\', ''), '\/', ''), '\"', ''), '?', ''), '\'', ''), '&', ''), '!', ''), '.', ''), ' ', '-'), '--', '-'), '--', '-')) AS `post_name`
@jonathanmoore
jonathanmoore / gist:2640302
Created May 8, 2012 23:17
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@gabrielbauman
gabrielbauman / CardType.java
Last active December 13, 2023 04:21
A Java enum representing credit card types (Visa, Mastercard etc) that can detect card type from a credit card number.
package com.gabrielbauman.gist;
import java.util.regex.Pattern;
public enum CardType {
UNKNOWN,
VISA("^4[0-9]{12}(?:[0-9]{3}){0,2}$"),
MASTERCARD("^(?:5[1-5]|2(?!2([01]|20)|7(2[1-9]|3))[2-7])\\d{14}$"),
AMERICAN_EXPRESS("^3[47][0-9]{13}$"),
@mlvea
mlvea / currencies.json
Created March 17, 2015 16:07
Common currencies as an array
[
{
"symbol": "$",
"name": "US Dollar",
"symbol_native": "$",
"decimal_digits": 2,
"rounding": 0,
"code": "USD",
"name_plural": "US dollars"
},
@v0lkan
v0lkan / nginx.conf
Last active April 2, 2024 18:25
Configuring NGINX for Maximum Throughput Under High Concurrency
user web;
# One worker process per CPU core.
worker_processes 8;
# Also set
# /etc/security/limits.conf
# web soft nofile 65535
# web hard nofile 65535
# /etc/default/nginx
@hootlex
hootlex / laravellocal.md
Last active May 3, 2024 08:06
Run laravel project locally

##Windows users:

cmder will be refered as console

##Mac Os, Ubuntu and windows users continue here:

  • Create a database locally named homestead utf8_general_ci
@cvan
cvan / HOWTO.md
Last active May 7, 2024 15:23
How to serve a custom HTTPS domain on GitHub Pages with CloudFlare: *FREE*, secure and performant by default

Instructions

CloudFlare is an awesome reverse cache proxy and CDN that provides DNS, free HTTPS (TLS) support, best-in-class performance settings (gzip, SDCH, HTTP/2, sane Cache-Control and E-Tag headers, etc.), minification, etc.

  1. Make sure you have registered a domain name.
  2. Sign up for CloudFlare and create an account for your domain.
  3. In your domain registrar's admin panel, point the nameservers to CloudFlare's (refer to this awesome list of links for instructions for various registrars).
  4. From the CloudFlare settings for that domain, enable HTTPS/SSL and set up a Page Rule to force HTTPS redirects. (If you want to get fancy, you can also enable automatic minification for text-based assets [HTML/CSS/JS/SVG/etc.], which is a pretty cool feature if you don't want already have a build step for minification.)
  5. If you
@saadtazi
saadtazi / app.js
Created July 19, 2016 11:52
passport multiple strategies
const express = require('express');
const cons = require('consolidate');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const passport = require('passport');
const FacebookStrategy = require('passport-facebook').Strategy;
const LocalStrategy = require('passport-local').Strategy;
const ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;
@jecyhw
jecyhw / AjaxAwareAuthenticationEntryPoint.java
Last active February 10, 2022 05:59
spring boot ajax session timeout
public class AjaxAwareAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {
public AjaxAwareAuthenticationEntryPoint(String loginFormUrl) {
super(loginFormUrl);
}
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
String ajaxHeader = ((HttpServletRequest) request).getHeader("X-Requested-With");
if ("XMLHttpRequest".equals(ajaxHeader)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Ajax Request Denied (Session Expired)");
@maheshwaghmare
maheshwaghmare / social-share-url-patterns.txt
Created May 13, 2017 09:54
Social Share URL Patterns. E.g. Facebook, Twitter, Google+, Pintrest, LinkedIn, Buffer, Digg etc.
Sharer : https://www.facebook.com/sharer.php?u={url}
Twitter : https://twitter.com/intent/tweet?url={url}&text={title}&via={via}&hashtags={hashtags}
Google : https://plus.google.com/share?url={url}
Pinterest : https://pinterest.com/pin/create/bookmarklet/?media={img}&url={url}&is_video={is_video}&description={title}
LinkedIn : https://www.linkedin.com/shareArticle?url={url}&title={title}
Buffer : https://buffer.com/add?text={title}&url={url}
Digg : http://digg.com/submit?url={url}&title={title}
Tumblr : https://www.tumblr.com/widgets/share/tool?canonicalUrl={url}&title={title}&caption={desc}
Reddit : https://reddit.com/submit?url={url}&title={title}
StumbleUpon : http://www.stumbleupon.com/submit?url={url}&title={title}