Skip to content

Instantly share code, notes, and snippets.

@lucaswxp
lucaswxp / make raw https request in golang using tls.go
Created November 29, 2021 00:00
make raw https request in golang using tls
package main
import (
"crypto/tls"
"io"
"log"
)
func main() {
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] user request to connect modem
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] simple connect started...
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] PIN: unspecified
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] operator ID: unspecified
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] allowed roaming: yes
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] APN: gprs.oi.com.br
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] IP family: ipv4v6
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] allowed authentication: unspecified
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] User: oi
Sep 10 13:42:47 3182c51 ModemManager[1389]: [modem0] Password: oi
@lucaswxp
lucaswxp / mongodb golang insert any json.go
Last active October 25, 2018 18:52
mongodb golang insert unknown/unstructured json document into collection - This function takes a interface{} and returns a structured bson.Document
import (
"github.com/mongodb/mongo-go-driver/bson"
)
func formatDocument(evdata interface{}) *bson.Document {
doc := bson.NewDocument()
for k, v := range evdata.(map[string]interface{}) {
switch t := v.(type) {
case map[string]interface{}:
<a rdz-modal="contato">Abrir modal contato</a>
.directive('rdzModal', function($rootScope){
return {
restrict: 'A',
link: function(scope, element, attrs){
alert(attrs.rdzModal) // ISSO E UMA STRING
}
}
@lucaswxp
lucaswxp / read all cookies as array javascript.js
Created June 8, 2015 12:04
read all cookies as object/array javascript
function readCookies() {
var cookies = document.cookie.split(';'),
r = {};
for(var i=0;i < cookies.length; i++) {
var c = cookies[i],
sep = c.indexOf('=');
r[c.substr(1, sep-1)] = c.substr(sep+1);
}
return r;
@lucaswxp
lucaswxp / CakePHP script for generating pot translations files.md
Last active August 29, 2015 14:19
CakePHP script for generating pot translations files

This script executes cake i18n extract with all the defaults args and returns the command output.

function extractPotFiles(){
  $app = ROOT . DS . APP_DIR;
  $cake = $app . DS . 'Console' . DS . 'cake';
  $olddir = getcwd();
  chdir($app);

  $descriptorspec = array(
 0 =&gt; array("pipe", "r"), // stdin is a pipe that the child will read from
@lucaswxp
lucaswxp / Check field exists in model django snippet.md
Last active June 30, 2024 03:00
Check field exists in model django snippet

In your models.py put:

from django.db import models

@classmethod
def model_field_exists(cls, field):
    try:
        cls._meta.get_field(field)
 return True
@lucaswxp
lucaswxp / socket.io force new connection not working fix.md
Last active August 29, 2015 14:16
socket.io force new connection not working fix

Socket.io connected the first time, but after disconnected, I couldn't connect again manually.

For me, the flags 'force new connection' and 'forceNew' wasn't working properly like some places says it should, and I couldn't find any way around it. Using socket.io 1.3.5, this is what I did to fix it:

var once = false;

function getSocket(){
 var socket = io({path: '/socket.io'}, {'force new connection':true});
@lucaswxp
lucaswxp / gist:766faddb92dd219d7ca0
Created February 12, 2015 17:56
Disable bodyparser in sails 0.9.x

In config/local.js just set bodyParser to return a placeholder function:

module.exports.express.bodyParser = function(){
  return function(req, res, next){ next(); }
}

Setting the property to false won't work because of a bug, so that's the best we got.

<!-- EMAIL CONFIG -->
<email_settings>
<recipients to="point_to_field:subject" cc="" bcc="" />
<smtp auth="yes" host="" username="" password="" secure_type="tls" port="587" />
<subject>Someone is getting in touch with you!</subject>
</email_settings>
<!-- FIELDS SETTINGS -->
<fields>
<new_radio_list name="subject" label="Subject: ">