Skip to content

Instantly share code, notes, and snippets.

@troystribling
troystribling / RememberMeAuthStrategy.scala
Last active January 1, 2017 08:32
Scalatra 2.2 Sentry implemented for username/password and cookie authentication.
package lib
import org.scalatra._
import org.scalatra.util.RicherString._
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
import org.scalatra.auth.{ScentrySupport, ScentryStrategy}
import net.iharder.Base64
import java.util.Locale
import io.Codec
@ilguzin
ilguzin / nginx_redirect_2named_location
Created November 6, 2013 07:03
NGINX: Redirect from current location into named location
# Use only codes greater than 418, do not use common status codes 404, 402, 403, etc
location /js {
error_page 418 = @backend; return 418;
}
location /data {
error_page 418 = @backend; return 418;
}
@mrded
mrded / foo.module
Created October 31, 2013 13:46
Drupal: Taxonomy terms as autocomplete using form API.
<?php
function bar_form($form, &$state) {
$form['bar'] = array(
'#type' => 'textfield',
'#title' => t('Bar'),
'#autocomplete_path' => 'taxonomy/autocomplete/field_bar_term', // Field name here.
'#element_validate' => array('foo_taxonomy_autocomplete_validate'),
);
@TahaSh
TahaSh / index.html
Created December 9, 2016 12:45
Reusable Autocomplete-Input Component in Vue 2.1
<title>Vue Awesome Autocomplete</title>
<link rel="stylesheet" href="https://unpkg.com/bulma/css/bulma.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="style.css">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="app">
<autocomplete-input
:options="options"
@select="onOptionSelect"
@LostKobrakai
LostKobrakai / post.md
Last active April 7, 2020 20:07 — forked from nahtnam/post.md
Using Laravel-Mix with Phoenix

Introduction

Laravel-Mix is "an elegant wrapper around Webpack for the 80% use case". It has nothing to do with Elixir's Mix and does not require Laravel to work!

Set up

Create a new phoenix application with mix phx.new. You may choose to add the --no-brunch flag to stop brunch from being intiailized, but I personally prefer leaving that in and replacing brunch so that the folder structure is set up for me.

$ mix phx.new demo

Install Laravel-Mix

@arigesher
arigesher / responsive-flickr-embeds
Last active October 26, 2020 08:20
JQuery code to make Flickr embeds responsive (and resize correctly when loading in a mobile browser). See http://ari.gesher.net/photos-the-gesher-world-tour/ for a working example.
$(document).ready(function() {
$("#pics iframe").each(function(index) {
var ratio = $(this).height() / $(this).width();
var origHeight = $(this).height();
var origWidth = $(this).width();
var self = this;
// bind to window with closure that references the
// iframe since the iframe doesn't get resize events
// until (you know) we resize it.
$(window).resize(function() {
@7h3rAm
7h3rAm / internet.py
Last active April 26, 2021 20:57
Quick Internet Connectivity Test: Invokes a connect on Google's public DNS server: 8.8.8.8:53/TCP with a socket timeout of 1 second.
import socket
def internet(host="8.8.8.8", port=53, timeout=3):
"""
Host: 8.8.8.8 (google-public-dns-a.google.com)
OpenPort: 53/tcp
Service: domain (DNS/TCP)
"""
try:
socket.setdefaulttimeout(timeout)
@piekie
piekie / RootUtils.java
Last active July 30, 2021 08:09
Utils : Kill and Force-Stop functions for android app.
public class RootUtils {
private static Process su;
public static void gainRoot() {
try {
su = Runtime.getRuntime().exec("su");
} catch (IOException e) {
e.printStackTrace();
}
@tsupo
tsupo / convIsbn.js
Created May 8, 2009 18:43
covert code between ISBN10 and ISBN13
/* convISBN.js : converter ISBN10 <-> ISBN13 */
/* Copyright (c) 2007 by H.Tsujimura <tsupo@na.rim.or.jp> */
/* Distributed by LGPL. */
/* this script written by H.Tsujimura 20 Jan 2007 */
function convISBN13toISBN10(str) {
var s;
var c;
var checkDigit = 0;
var result = "";
@Hades32
Hades32 / elixir-npp.xml
Created October 14, 2014 18:46
Simple syntax highlighting for Elixir for Notepad++
<NotepadPlus>
<UserLang name="Elixir" ext="ex exs" udlVersion="2.1">
<Settings>
<Global caseIgnored="no" allowFoldOfComments="yes" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="yes" Keywords4="yes" Keywords5="yes" Keywords6="yes" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00# 01 02 03/* 04*/</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>